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.
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.
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.
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!
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.