Not Stopping Animation

The title is pretty self-explanatory. My action animation will not stop when being activated from a button on screen. Code:

local playing = false
script.Parent.MouseButton1Down:Connect(function()
	local character = game.Players.LocalPlayer.Character
	local hum = character:FindFirstChild("Humanoid")
	local anim = hum.Animator:LoadAnimation(game:GetService("StarterPlayer").StarterCharacterScripts.CtoCrawl.Crawl)
	if not playing then
		hum.WalkSpeed = 8
		anim:Play()
		playing = true
	elseif playing then
		anim:Stop()
		hum.WalkSpeed = 16
		playing = false
	end
end)

Thanks to anyone who helps! :slight_smile:

Change:

To: if playing == false then

Also, you should change:

To: elseif playing == true then

1 Like

It’s still not working. The game let’s me go into the animation (Crawl animation) but I can’t get out. The speed still speeds up as if I wasn’t in the animation, but it’s just stuck.

Is there anything in the output?

1 Like

No, nothing at all.

wordlimitwordlimit

local playing = false
script.Parent.MouseButton1Click:Connect(function()
	local character = game.Players.LocalPlayer.Character
	local hum = character:FindFirstChild("Humanoid")
	local anim = hum.Animator:LoadAnimation(game:GetService("StarterPlayer").StarterCharacterScripts.CtoCrawl.Crawl)
	if playing == false then
		hum.WalkSpeed = 8
		anim:Play()
		playing = true
	else
		anim:Stop()
		hum.WalkSpeed = 16
		playing = false
	end
end)

Rewrote the script for you, see if that works.

1 Like

Nope, same thing is happening. I know it’s definitely anim.Stop() that’s not working. The walkspeed goes back to normal, but it’s just not stopping the animation. Thanks for trying though.

It must be an issue with the animation, try move these outside of the event:

I am now seeing this error in my output:
image

Try change it to: local hum = character:WaitForChild("Humanoid")

I am getting the same error. Isn’t that what I had it as before?

You had it as FindFirstChild().

I would try create a variable for the animator first, and then see if it works.

1 Like

My mistake. I copied over the wrong one :sweat_smile:

No worries! Glad I could help!

1 Like