Animation debounce question

Hello, I made the script for animation to play when player clicking on the button, but it doesn’t work if I want it to play until player click again. I tried making something like debounce but it doesn’t work. Usually with :LoadAnimation() it works but I’m trying new method AnimationTrack()
Here’s a script I made


Can you say why it’s not working like I need?
Thank you!

1 Like

You’re not changing the value of playing once the animation has completed. Try placing this after the playing = true statement.

animationTrack.Stopped:Wait()
playing = false
1 Like

Do you mean like this?image

Yeah,that’s what I had in mind.

That’s not working even if that supposed to work

If it’s a dance, don’t you want it to keep playing until the player wants to stop, instead of just playing once? Also, I moved the animator and animationTrack variable definitions to outside the scope of the function to prevent the animation from being loaded every time.

Try this:

local animator = humanoid:FindFirstChildOfClass("Animator")
local animationTrack = animator:LoadAnimation(animation)

local playing = false

local function PlayDance()
  if playing then
    playing = false
    print("Stopping animation")
    animationTrack:Stop()

  else
    playing = true
    print("Starting animation")
    animationTrack.Looped = true
    animationTrack:Play()
  end
end
1 Like

Wait it is working as I need! Thank you so much!