Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Make sword strike animation wait untill the animation is done before allowing it to play agaom?

I need help. When I click my mouse it plays the animation, but if I keep clicking it repeats it. How could I make it wait for the animation to play before being able to play again? This is what I have so far. Thanks.

local animation = script.Parent.Animation
local Tool = script.Parent
local animTrack = nil

Tool.Activated:connect(function()
	animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)
	animTrack:Play()	
end)

2 answers

local animation = script.Parent.Animation
local Tool = script.Parent
local animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)

Tool.Activated:connect(function()
	if animTrack.IsPlaying == false then
		animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)
		animTrack:Play()
	end
end)

Here is the script;

local animation = script.Parent.Animation
local Tool = script.Parent
local animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)
local canplay = true

Tool.Activated:connect(function()
	if canplay then
		canplay = false
		animTrack:Play()
		animTrack.Stopped:wait()
		canplay = true
	end
end)

canplay is a bool value, and a debouncer. If you do not know what a debouncer is then I would suggest looking it up on YouTube.

This discussion is preserved as it was. New answers, comments, and votes are closed.