I was making this combat system and noticed that every time I go to punch, it creates a new :LoadAnimation(), which then stacks up on the humanoid’s Animator which then causes it to eventually error and exceed its limit (Here’s what it says: “AnimationTrack limit of 256 tracks for one Animator exceeded”).
I was wondering if there was any way to check if the Animator has the animation loaded before loading it again to avoid it stacking? Thanks again!
script:
local animation = Instance.new("Animation", humanoid)
animation.AnimationId = comboAnimations[combo]
animation.Name = "Punch"
local loadAnimation = humanoid.Animator:LoadAnimation(animation)
loadAnimation:Play()
animation:Destroy()
Guessing you are making the animation Instance inside an event.
Well, guess what you don’t have to
just do
local animation = Instance.new("Animation", humanoid)
animation.AnimationId = comboAnimations[combo]
animation.Name = "Punch"
local track = humanoid.Animator:LoadAnimation(animation)
local function onPunch(example)
track:Play()
end
onPunch("Random argument for the fancy lol")
I created the animation and the loadanimation outside of the event, and then call the function when its needed, but only the first animation in the table plays due to the combo being 1. Is there something wrong?
Edit: Here’s the script:
local animation = Instance.new("Animation", humanoid)
animation.AnimationId = comboAnimations[combo]
animation.Name = "Punch"
local loadAnimation = humanoid.Animator:LoadAnimation(animation)
local function playAnim(c)
animation.AnimationId = comboAnimations[c]
loadAnimation:Play()
end
What’s the reason you’re constantly making new animations rather than just storing an instance?
If you’re reusing the same punch animation there’s no reason to keep reloading it.
For items and tools I typically load the animation and just parent it in the character or tool itself.
I just reuse that animation rather than doing LoadAnimation() every time.
Only when said tool is dropped by the player or the player respawns the animation track is destroyed.
Reloading it is unnecessary and can also mess up things like blending/mixing animations since destroying it makes it stop abruptly afaik and just looks a little yanky.
If your fighting game works with classes where every class has it’s own moveset, just keep the animation tracks loaded, parent them in the player and just keep using those rather than destroying them.
Saves you lines of code and you shouldn’t run into this problem ever again unless for some reason you load more than 256 animations.
My guess is that your constant animation loading is causing a buildup of animation data that needs time to get cleaned up or released after the track is destroyed and you’re creating animations faster than the engine can clean up.