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

Trying to get an Animation to stop playing?

Okay so, the animation is set to loop, I'm just trying to get the Animation to stop playing after once the character stops moving. I have the if Anim then Anim:Stop() to stop it from playing upon player join

local Anim
humanoid.Running:Connect(function(speed)
    CurrentAnim = "Walking"
    if speed > 0 then
	   local Animation = Instance.new('Animation')
        Animation.AnimationId = WalkAnimID
       Anim = humanoid:LoadAnimation(Animation)
        Anim:Play()
    else
        if Anim then
	Anim:Stop()
	if speed == 0 then
		Anim:Stop()
	end
 CurrentAnim = ""
        end
    end
end)

1 comment

1

I would personally use GetPlayingAnimationTracks and stop all animations made from the Running animation ID. It helps stop the animation glitches. Reply if you'd like an example in answers

1 answer

Simply call the GetPlayingAnimationTracks method on the humanoid, and set a pointer to what it returns like so:

local Animations = humanoid:GetPlayingAnimationTracks();

Then, go through them one by one:

for Key, Value in next, Animations do --Key is the current animation # you are on & Value is the pointer to the current animation
--\\Code//--
end;

Now call the stop method on 'value':

Value:Stop();

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