Stopping animation

Hello!

How can I stop any playing animations on this player?

Thanks!!

if emoteid == 1 then
		-- Threaten
		local animcheer = script.Parent.Threaten
		local Hum = game.Workspace[plrf].Humanoid
		local anim = Hum:LoadAnimation(animcheer)
		-- stop all other animations and set walking speed to 0 
		anim:Play()
	elseif emoteid == 2 then
		-- Cry
		local animcheer = script.Parent.Cry
		local Hum = game.Workspace[plrf].Humanoid
		local anim = Hum:LoadAnimation(animcheer)
		anim:Play()
	end

Maybe make a table with all of the animations and then use a for loop to stop them all. Not sure if this is the most efficient way to do it though.

local Animations = {
	animation1;
	animation2;
}

for _, animation in pairs(Animations) do
	if animation.IsPlaying then
		animation:Stop()
	end
end

Edit: i forgot that .IsPlaying won’t work on an animation instance. Do what the post below said and use Animator:GetPlayingAnimationTracks()

Animators can return all playing AnimationTracks with Animator:GetPlayingAnimationTracks()

Simply loop over all the animation tracks and stop them.

Note: not sure if this will mess up core animations such as the default walk and stuff but you can try

local Animator = Hum:FindFirstChildWhichIsA("Animator")
local PlayingAnimationTracks = Animator:GetPlayingAnimationTracks()

for _, Track in PlayingAnimationTracks do
     Track:Stop()
end
1 Like

Mmm… Im getting an error

ServerScriptService.Emotes.AnimationControl:26: attempt to call missing method 'Stop' of table  -  Server - AnimationControl:26
Line: 'a:Stop()'

Can you send the whole script?

You are trying to call Animation:Stop() on the whole table of animation tracks. You would have to loop through the table and individually stop each one.

local tracks = animator:GetPlayingAnimationTracks()
for _, track in tracks do
    track:Stop()
end

thanks man, have a good day

30 chs

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.