How to let a animation finish its loop

Hi all,

I have this script that plays an animation on a tool whenever i press the mousebutton. However when you spam the mousebutton key, the animation will not finish but is spamming aswell. Is there a way to prevent the animation spamming? So the animation first finish its loop and than start again if the mousebutton is pressed?

local Tool = script.Parent
local Animation = Tool.Dig

Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character.Humanoid

	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
	Humanoid.WalkSpeed = 0
	AnimationTrack.Stopped:Wait()	
	Humanoid.WalkSpeed = 16
	
	-- proceed
	
end)

i use Animator:GetPlayingAnimationTracks() to see which ones are playing. It returns a table so you can ask if the current animation is part of the PlayingTracks table

https://developer.roblox.com/en-us/api-reference/function/Animator/GetPlayingAnimationTracks

I found a solution by adding in this:

	script.Disabled = true
	wait (2) --time it takes for the animation
	script.Disabled = false

thank you for your reply :slight_smile: