How to stop a loop animation?

I wrote a script which plays an animation when an item is equipped, but the problem is when I unequip the item it still plays, can someone please help?

Script:

https://gyazo.com/1cd564e5de048899c53299fe3f74e305

Note: Idle Animation is looped.

4 Likes

You forgot to loop the animation before exporting.

4 Likes

Ok, so I set it to loop, but how will I make it so that it stops when the item is unequipped?

2 Likes
PaintballGun.Unequipped:Connect(function()
          EquipAnimationTrack:Stop()
end)

Though you will have to make the animation variable global.

3 Likes

Oh! I didn’t know you could just use Stop()! Thank you so much!

2 Likes

Still didn’t work. :sweat_smile:

https://gyazo.com/1cd564e5de048899c53299fe3f74e305

Still not fixed, if anyone know’s a solution please let me know. :sweat_smile:

you can get all playing animation tracks on a humanoid by doing Humanoid:GetPlayingAnimationTracks() and check for the one you want to stop

for i,v in pairs(Humanoid:GetPlayingAnimationTracks()) do
	if v.Animation.AnimationId == "AnimationId here" then
		v:Stop()
	end
end
11 Likes

I don’t really see the point of this if we already know and have already referenced which animation we want to stop. :sweat_smile:

its so that you can play/stop it from different scripts

1 Like

I can stop it from different scripts, I defined the animation track outside the remote event.

did my script not work for you?

1 Like

I don’t think it will, as I already have the animation referenced and if stopping it like that didn’t work then I don’t know what will.

give it a try, it should work, playing and stopping animations is weird that if you do :Play() on one block of code and try to use :Stop() in a different one it doesnt work, that code solves the issue, at least for me

1 Like

You can do:

for trackNumber, track in pairs(Humanoid:GetPlayingAnimationTracks()) do
    if track then
      track:Stop() -- This will stop every track of animation that is playing
   end
end
2 Likes

Ok! I will try it! Hopefully it works.

There’s an error in the code, I have edited it, please copy the code now

thats the same as my code however mine specifies which animation to stop, stopping all tracks will stop all movement and idle animations (until you trigger them again of course)

1 Like

I know, I just like doing that for some reason, I am weird you never know

1 Like

Can you paste the code here instead of a picture? (If it doesn’t get fixed.)

1 Like