How can I stop a animation?

How can I stop a animation ? My try below doesnt work…

script.Parent.Salute.MouseButton1Click:Connect(function()
	loadanim = humanoid:WaitForChild("Animator"):LoadAnimation(script.Parent.Salute:WaitForChild("SaluteAnim"))
	
	if b_active == false then 
		loadanim:Play()
		b_active = true
	else 
		loadanim:Stop()
		b_active = false
	end
end)

try this

script.Parent.Salute.MouseButton1Click:Connect(function()
	loadanim = humanoid:WaitForChild("Animator"):LoadAnimation(script.Parent.Salute:WaitForChild("SaluteAnim"))
	
	if not loadanim.IsPlaying then 
		loadanim:Play()
	else 
		loadanim:Stop()
	end
end)

Its not working ( no error code )

Hmmm …
First you don’t need to reload the anim every time a player click so set your variable for first !
It should look like this :

local Button = script.Parent.Salute
local Animator = humanoid:WaitForChild("Animator")
local Animation = Button:WaitForChild("SaluteAnim")
local LoadedAnimation = Animator:LoadAnimation(Animation)

Button.MouseButton1Click:Connect(function()
	if not LoadedAnimation.IsPlaying then 
		LoadedAnimation:Play()
	else 
		LoadedAnimation:Stop()
	end
end)

But do you want to play the anim and after stop it or when the player click play it and stop it when a player re click ?
Have a nice day !

“First you don’t need to reload the anim every time a player click”
I made this because Im having many animations in that script and yes I want to make it that you can click on a button then the animation starts and if you click again it stops playing but it won’t stop. I also dont get any kind of error code.

1 Like

Yes but if you reload your animation every time you click it will load another anim so it won’t stop the good anim and so you anim will never stop !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.