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
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