Hitting the AnimationTrack limit

I have an item in my game which toggles an animation on the player’s character once it’s equipped. The animation stops playing once the item is unequipped.
For some reason, I’m hitting the animation track limit, even though the animation is loaded once on the client. Each new error is displayed once the character makes a movement.

Preview:

Console:

The code I wrote for the item:

local plr = game.Players.LocalPlayer
local anim = Instance.new('Animation') anim.AnimationId = -- my animation id is here
local tool = script.Parent
local db = false
local h = workspace:WaitForChild(plr.Name):WaitForChild('Humanoid')
local track : AnimationTrack = h:LoadAnimation(anim)

track.Priority = Enum.AnimationPriority.Action4
anim:Destroy()

tool.Equipped:Connect(function()
	if not db then
		db = true
		track:Play()
		task.wait(0.25)
		db = false
	end
end)

tool.Unequipped:Connect(function()
	track:Stop()
end)

Please let me know if you have any ideas or a possible solution.

Well, personally I think that it’s the default Roblox animations script that’s causing this mess, but I decided to post the code incase there’s something I haven’t noticed or should’ve added.

Yes, that one. I’m definitely going to be checking it out to see if there’s anything that could’ve caused this.

1 Like

Default Animate script loads animations multiple times, and then, later on, destroys the loaded tracks.
The errors start to appear when I equip my item.

изображение_2022-04-10_152547625

Although, I have a strange feeling that I am not entirely correct here. If you know anything that could additionally help, please let me know!

The script you posted only loads the animation once, do you have any other scripts you’re using that load animations?

Try changing the animation priority to core, instead of action?

I have another item that uses an animation, but it doesn’t seem to affect this.

I’m pretty sure that won’t change much, but thanks for the idea! I’ll definitely check it out once I get home.

I don’t see anything immediately wrong with this code… Are you sure you have no third party scripts that could be causing this?

I recommend trying a few different print debugging methods. For example:

local AnimationTracks = humanoid:GetPlayingAnimationTracks()
print(AnimationTracks) 

This will only print currently playing Animation Tracks. You might find out what animation is causing it or you might not with this method…

Another method you can try is to create a blank array and insert the track into it every time you load an animation track. Then print the contents of the array within a loop every few seconds to see if it’s increasing at all.

Hope this helps! If you have any further questions feel free to ask!

2 Likes

Many thanks for your suggestion! I might be able to find the main issue of the problem using your method.

image

I’ve done the debugging again and now I’m 100% certain it’s the default Animate script that is causing this. It attempts to play animations, but doesn’t stop them because they are interfering with the animation I played.

The only solution I see right now is changing the values inside the Animate script to my animation. It’s kind of a dodgy method, but I don’t see any other workarounds.

1 Like