Inconsistency with Humanoid:GetPlayingAnimationTracks?

I have a function that stops any AnimationTrack on an NPC. This is how the function goes:

		if self.AnimationTracks[Name].Looped then
			self.AnimationTracks[Name].Looped = false
		end
		
		repeat RunService.Stepped:Wait() until self.AnimationTracks[Name].IsPlaying == false
		
		for _, v in pairs(self.GiantModel.Humanoid:GetPlayingAnimationTracks()) do
			print(v == self.AnimationTracks[Name], v.IsPlaying)
		end

There is something wrong with Humanoid:GetPlayingAnimationTracks(). It prints the AnimationTrack that I was stopping (by stopping, I mean waiting for it to finish), even though it’s .IsPlaying property is set to false.

Anyone know what could be going wrong?

Compare the tracks by the AnimationId instead, your comparing an AnimationTrack to an Animation.

for _, v in pairs(self.GiantModel.Humanoid:GetPlayingAnimationTracks()) do
    print(v.AnimationId == self.AnimationTracks[Name].AnimationId, v.IsPlaying)
end

What? GetPlayingAnimationTracks() returns an array of AnimationTracks, and self.AnimationTracks only contains AnimationTracks.

Furthermore, the first condition prints true, which means that variable v and self.AnimationTracks[Name] are the same Instance, which is relevant to pointing to the fact that the problem may exist on Roblox’s end.

Its not on roblox’s end I have use that function multiple times you must be doing something wrong.

Well, through an extensive process of debugging, I’ve tested multiple hypothesis until I’ve ran out of ideas to prove and disprove. I know that print statements don’t lie, and the print statements show above the following facts:

1 - The animation track is set to not be looped. This means that eventually, it will be stopped once it finishes playing.
2 - It waits until AnimationTrack.IsPlaying is set to false. Which means that it waits until the track stops.
3 - It appears in the :GetPlayingAnimationTracks() array, which shouldn’t happen, because it waited until AnimationTrack.IsPlaying was set to false.

I have no idea where I can go wrong in such a simplistic system, which is why I came here to see if you guys had any clue. No offense, but if you don’t have an idea of what might be going wrong I don’t think you should put meaningless blame. I can give you other details/code outside the scope if you’d like, but as I said, it’s quite simple code.

1 Like

Hi i just remembered that there is a bug with the looped property being set through a script, the change will not replicate to the server, so I think that is why it is still being returned. AnimationTrack.Looped Does Not Replicate - #8 by Life_Blox. For now you can only manually edit the looped property through the animation editor.

This code segment seems to be part of a bigger script? Is it a localscript or serverscript? Maybe try doing something as simple as possible in a different script so that you can pin down the cause of the problem.

This was the cause of the problem.

1 Like