# Not play animation while another animation is playing (SOLVED)

**URL:** <https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297>\
**Category:** Questions\
**Created:** [May 23, 2020, 11:20am UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297 "2020-05-23T11:20:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sungbum](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sungbum/32/20578_2.png) [@Sungbum](https://forum.defold.com/u/Sungbum)\
**Post date:** [May 23, 2020, 11:20am UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/1 "2020-05-23T11:20:47Z")

</div>

How can you stop your game object from playing an animation while another animation is already going on.  
My game object attacks when I click my mouse. I want to make my game object to not play the attack animation if attack animation is already going on.

---

<div class="post-metadata">

**Author:** ![Grass\_dev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/grass_dev/32/20592_2.png) [@Grass\_dev](https://forum.defold.com/u/Grass_dev)\
**Post date:** [May 23, 2020, 11:33am UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/2 "2020-05-23T11:33:50Z")

</div>

can you show your script?  
because i did not realise your question.

---

<div class="post-metadata">

**Author:** ![88.josh](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/88.josh/32/20137_2.png) [@88.josh](https://forum.defold.com/u/88.josh)\
**Post date:** [May 23, 2020, 11:57am UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/3 "2020-05-23T11:57:37Z")

</div>

you need some if statements and some self.properties.

show us your script and I’ll show you what i mean

---

<div class="post-metadata">

**Author:** ![Sungbum](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sungbum/32/20578_2.png) [@Sungbum](https://forum.defold.com/u/Sungbum)\
**Post date:** [May 23, 2020, 12:00pm UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/4 "2020-05-23T12:00:53Z")

</div>

```
if action_id == hash("touch") and action.pressed then 
		msg.post("#sprite", "enable")
		sprite.play_flipbook("#sprite", "attack", anim_done)
end

```

With this code, when i click, the animation restarts every time. I want to make sure that animation doesn’t start again until it is over.

---

<div class="post-metadata">

**Author:** ![88.josh](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/88.josh/32/20137_2.png) [@88.josh](https://forum.defold.com/u/88.josh)\
**Post date:** [May 23, 2020, 12:12pm UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/5 "2020-05-23T12:12:10Z")

</div>

```lua
if action_id == hash("touch") and action.pressed then 
	msg.post("#sprite", "enable")
	if self.attacking == nil then
		sprite.play_flipbook("#sprite", "attack", anim_done)
		self.attacking = true
	end
end

```

Now, you have a property, called self.attacking, which turns to true when the attack begins.

You also can’t start attacking unless self.attacking equals nil.

The last part is putting

```lua
self.attacking = nil

```

in your function called anim\_done. That means self.attacking is reset to nil once the attack is done, and can be called again

---

<div class="post-metadata">

**Author:** ![Sungbum](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sungbum/32/20578_2.png) [@Sungbum](https://forum.defold.com/u/Sungbum)\
**Post date:** [May 23, 2020, 12:48pm UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/6 "2020-05-23T12:48:01Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 23, 2020, 6:09pm UTC](https://forum.defold.com/t/not-play-animation-while-another-animation-is-playing-solved/65297/7 "2020-05-23T18:09:59Z")

</div>

And here’s another example showing this: [publicexamples/examples/play\_animation at master · britzl/publicexamples · GitHub](https://github.com/britzl/publicexamples/tree/master/examples/play_animation)
