How Do I Make Debounce On This Animation Script?

local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://8885497056”

local trackanimation = nil
local playability = true

function playAnimation (animationSource)
if playability == true then
local plr = game.Players.LocalPlayer
trackanimation = plr.Character.Humanoid:LoadAnimation(animation)

	trackanimation.KeyframeReached:Connect(function()
		print("Animation successfully played!")
	end)
	trackanimation:Play()
end

end
script.Parent.MouseButton1Click:Connect(playAnimation)

Looks like you already have a debounce playability. Set playability = false right after trackanimation:Play() and set it back to playability = true in your KeyframeReached connection. This will make it unplayable until the keyframe at the end was reached. You might also want to be listening to .Stopped on the animation track instead too, then you may not need a connection at all and could just trackanimation.Stopped:wait()

1 Like

trackanimation.Stopped:Wait(3) didnt work could u please help

It’s just :wait() the documentation doesn’t specify that you can pass it a number to explicitly wait for.
Check out AnimationTrack.Stopped (roblox.com)

1 Like

Something like this maybe:

local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://8885497056”

local trackanimation = nil
local playability = true

function playAnimation (animationSource)
	if(not(playability))then return end --If Not playable then exit function
	playability = false --Mark now as not playable
	local plr = game.Players.LocalPlayer
	trackanimation = plr.Character.Humanoid:LoadAnimation(animation)

	trackanimation.KeyframeReached:Connect(function()
		print("Animation successfully played!")
	end)
	trackanimation:Play()
	trackanimation.Stopped:Wait()
	playability = true --Now that the animation is over, mark it playable again
end
script.Parent.MouseButton1Click:Connect(playAnimation)
1 Like