Problem with animation script

I have a problem with animation, for some reason its can’t stop playing while you press “Stop Animation” did i do something wrong?

here the code:

script.Parent.MouseButton1Click:Connect(function(player)
	if script.Parent.Text == "Start Animation" then
		local User = game.Players.LocalPlayer
		local Character = User.Character
		local Humanoid = Character:WaitForChild("Humanoid")
		local Animation = script.Animation
		local AnimationTrack = Humanoid:LoadAnimation(Animation)
		AnimationTrack:Play()
		EventStart:FireServer(player)
		wait(1)
		script.Parent.Text = "Stop Animation"
		script.Parent.Visible = true
	elseif script.Parent.Text == "Stop Animation" then
		local User = game.Players.LocalPlayer
		local Character = User.Character
		local Humanoid = Character:WaitForChild("Humanoid")
		local Animation = script.Animation
		local AnimationTrack = Humanoid:LoadAnimation(Animation)
		AnimationTrack:Stop()
		script.Parent.Visible = false
		script.Parent.Text = "Start Animation"
		EventEnd:FireServer(player)
	end
end)

thanks for helping :flushed:

1 Like

Try use AnimationTrack:Destroy() instead of :Stop()
Might work.

Nope, still doesnt work for some reason

Try do

for _,tracks in pairs(Humanoid:GetPlayingAnimationTracks ( )) do
tracks:Stop()
end
local Idle = Humanoid:LoadAnimation(Character.Animate.Idle.Animation1)
Idle:Play()

Tell me if it’s works

1 Like

It works! Thanks you so much, you just saved my life

1 Like