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

How do I stop an animation from playing?

How would I stop an animation without making another animation? I tried anim:Stop() but it didnt work.

local Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
play = false

Mouse.KeyDown:connect(function(Key)
	if(Key:lower() == "f") and play == false then
		anim = Player.Character.Humanoid:LoadAnimation(script.animTest)
		anim:Play()
		Player.Character.Humanoid.WalkSpeed = 20
		play = true
		
		if(Key:lower() == "f") and play == true then
		anim = Player.Character.Humanoid:LoadAnimation(script.animTest)
		anim:Stop()
		Player.Character.Humanoid.WalkSpeed = 16
		play = false
		
		end
		end
end)

5 comments

0

What's the name of the animation in the script?

0

anim

0

Can you post a small snipbit of the script?

0

yea

0

Instead of having to press the key again with the if statement, what you could do is after the first if statement is declared, put a wait(Any variable you want) and then anim:Stop()

2 answers

I'm not sure if you're wanting it to be timed; so here is what I came up with so that after a certain about of time; the animation will stop itself instead of having to KeyDown again. If this isn't what you wanted, you can let me know.

local Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Play = false

Mouse.KeyDown:connect(function(Key)
	if(Key:lower() == "f") and play == false then
		anim = Player.Character.Humanoid:LoadAnimation(script.animTest)
		anim:Play()
		Player.Character.Humanoid.Walkspeed = 20
		Play = true
		wait(5) -- Change this value to whatever you want
		anim:Stop()
		Player.Character.Humanoid.Walkspeed = 16 
		Play = false
	end
end)

2 comments

0

TImed isnt really what i was looking for, im making a script that when you press f your character plays an animation and runs(gun idle)

0

also the animation doesnt stop playing

You're doing it correctly. anim:Play() Plays it.. anim:Stop() Stops it. Works for my animations. Probably other error in the script.

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