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