I know there is a limit of 256x animation tracks a humanoid can load so i try to destroy the old loaded animations.
I have a tool that loads an animation when the parent switches to a parent of a humanoid(when its being equipped by a player or NPC).
When i set the tool to nil and then set it back to the same NPC then it checks if that same humanoid has the animations loaded and if the animation exists then it destroys them.
the issue is that when i call the destroy function on the animation track it wont get destroyed.
local tool = script.Parent
local isEquipped = false
local a = nil
function init()
print(3)
if tool.Parent and tool.Parent:FindFirstChildOfClass("Humanoid") and tool.Parent.Humanoid.Health > 0 and tool.Parent.Humanoid:FindFirstChildOfClass("Animator") then
local anims = tool.Parent.Humanoid:FindFirstChildOfClass("Animator"):GetPlayingAnimationTracks()
if #anims > 0 then
print(#anims)
for i,v in ipairs(anims) do
v:Destroy()
v = nil
end
end
isEquipped = true
if a == nil then
a = tool.Parent.Humanoid.Animator:LoadAnimation(script.Parent.testAnim)
a:Play()
end
end
end
init()
script.Parent.AncestryChanged:Connect(function(this,newParent)
init()
end)
it keeps adding up animation instead of destroying them