Animation Support

Hello! I am currently developing a tool that runs an eating animation and then returns the player back to holding the item. I want to prevent players from spam clicking the eating animation, and want the animation to fully play before being able to play it again.

I think I need to put a wait() somewhere here, but am unsure and would love some help.

script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
        animation:Play()
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)

You should make use of a debounce

local debounce = false
script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if not debounce then
			debounce = true
			animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
			animation:Play()
			animation.Stopped:Wait()
			debounce = false
		end
    end)
end)
1 Like