Animation not stopping when using a Track:Stop()

Hello, i have an issue where my animation wont stop when using Track:Stop(), its a looped animation running in a basic stat training script that is called via a RemoteEvent, i checked to see if it was running at all and it was, but it didn’t stop the animation and there are no errors.

if CommandType == "Magic" then
		local Animation = Instance.new("Animation")
		Animation.AnimationId = "http://www.roblox.com/asset/?id=".. AnimationDictionary["MeditateSit"]
		local Track = humanoid:LoadAnimation(Animation)
		
		local IdleAnimation = Instance.new("Animation")
		IdleAnimation.AnimationId = "http://www.roblox.com/asset/?id=".. AnimationDictionary["MeditateIdle"]
		local IdleTrack = humanoid:LoadAnimation(IdleAnimation)
		IdleTrack.Looped = true
		
		if Parameter == "Add" then
			PlayerStats.Magic.Value = PlayerMagic + (1450 + (PlayerLV * 50))
		elseif Parameter == "Start" then
			Track:Play()
			task.wait(1)
			
			IdleTrack:Play()
		elseif Parameter == "End" then
			IdleTrack:Stop() ---------------right here
		end
	end
2 Likes

You want Track to stop?

You only stopped the IdleTrack

Oh, sorry I see the problem

the “Track” animation isnt looped so i didnt need to stop it since it only played once but the “IdleTrack” is looped, the problem is the :Stop() function isnt stopping the looped animation.

oh i just read your edit lol

You need the :LoadAnimation outside of that if statement or the script thinks it’s a new one.

This should fix it.
Redefining it makes the script think it’s a whole new animation. (Which I think is stupid)

Yeah, I was being dumb for a minute.

1 Like

the :Stop() is in an if statement inside the if statement that has the :LoadAnimation, shouldn’t i be able to read from it there?

What I am saying is you are redefining this every time the if statement runs.

hmm i dont think im understanding, also i just ran print(IdleTrack.IsPlaying) and it came out as false, so thats another strange thing.

What I am saying is every time this line runs

It is making a whole new variable

Meaning it is not stopping the old track, but stopping the new one that was made

oh i see, ill try that, but that just throws all my organization out the window which sucks

Hm, you can try to use this

Humanoid:GetPlayingAnimationTracks()

It returns an array of all the tracks playing.

This might help out.

I don’t exactly know if it’ll make s difference, but you should be loading the animation via an Animator, that’s why when you do it with a Humanoid OR AnimationController it’ll be crossed out… because it’s deprecated.

2 Likes