New animations wont be played

i began to make a new game today. And i wanted to add a advanced movement that i had from a person on yt or at least custom animations like idle and walk/run. But after i made all these things and wrote the script to change ids in the animate script then it didnt work. I was getting errors.
“Failed to play animation: rbxassetid://85418475642350. AnimationTrack limit of 64 tracks exceeded for ‘VersacherS’, new animations will not be played.”

And it wasnt only about 1 animation. its making my animations stop playing at all. It makes it like when u enter the game everythings fine, but walk animation stops playing a few minutes later, then jump animation stops playing and so on.

HOW TO FIX IT?

1 Like

This might not be a Roblox bug. It looks like AnimationTracks are building up over time.
Every time Animator:LoadAnimation() is called, a new track is created, and if they aren’t reused or cleaned up, you can eventually reach the 64-track limit. After that, new animations won’t play.

The default Animate script usually reuses tracks, so it’s possible that the changes caused the animations to be loaded repeatedly during movement or state changes.

A possible fix is to load each animation once when the character spawns, store the tracks, and then only use :Play() and :Stop() instead of calling LoadAnimation again.

If it’s already in this state, you can try clearing the existing tracks once with:

for _, track in ipairs(humanoid.Animator:GetPlayingAnimationTracks()) do
    track:Stop()
    track:Destroy()
end

Then adjust the script so animations are loaded once and reused.

Hope this helps :slight_smile:

2 Likes

the part that i found familiar w what u sent
local anim = animTable[animName][idx].anim

if (anim ~= currentAnimInstance) then

	if (currentAnimTrack ~= nil) then
		currentAnimTrack:Stop(transitionTime)
		currentAnimTrack:Destroy()
	end

	currentAnimSpeed = 1.0

	currentAnimTrack = humanoid:LoadAnimation(anim)
	currentAnimTrack.Priority = Enum.AnimationPriority.Core

	currentAnimTrack:Play(transitionTime)
	currentAnim = animName
	currentAnimInstance = anim

	if (currentAnimKeyframeHandler ~= nil) then
		currentAnimKeyframeHandler:disconnect()
	end
	currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)

end

also guys, im a beginner scripter, sry if sometimes i dont understand things that r easy for u

This function is connected to the animator of the player. When an animation plays this function is called;

local Animator: Animator = Your animator

Animator.AnimationPlayed:Connect(function(AnimationTrack: AnimationTrack): nil
	
	local Animation:Animation = AnimationTrack.Animation -- Your animation

	while math.abs(AnimationTrack.WeightCurrent - AnimationTrack.WeightTarget) > 0.001 and task.wait() do end -- Wait until track fades in

	for _, Object:AnimationTrack in Animator:GetPlayingAnimationTracks() do -- Stops all of the animations under animator, except the one you just played
		
		if Object == AnimationTrack then continue end -- check to see if that's your animaton that just played
		
		Object:Stop()
		Object:Destroy()
		
	end

end)

This function is just copy and paste, just set Animator to the player’s animator.

How does this work?

when playing an animation you call

Animator:LoadAnimation("rbxassetid"..Id):Play(FadeTime, Weight, Speed)

This plays the animation, but it also triggers the function a showed above. Fadetime is how long it takes for one animation to fully hit it’s specified weight, if we stop all of the animations --the Fadetime is practicality useless; since there is only one animation playing the weight doesn’t mean anything, and this causes jitterness.

How can we fix it? Luau ( Roblox Lua ) does not show the Fadetime of the Animation, instead we use this;

while math.abs(AnimationTrack.WeightCurrent - AnimationTrack.WeightTarget) > 0.001 and task.wait() do end -- Wait until track fades in

WeightCurrent is how much weight the animation currently has, WeightTarget is the weight you entered when you played the Animation. By getting the difference of these two values, we can figure out how long the fade time is. All this line is saying is; Is Fadetime over? if not wait an extra frame and do the calculation again. This yields the script, when we finally waited for Fadetime, then we stop all of the animations, except the one we just played

i tried my best and its still reaching 64 tracks

function playAnimation(animName, transitionTime, humanoid)
	local roll = math.random(1, animTable[animName].totalWeight)
	local origRoll = roll
	local idx = 1
	while (roll > animTable[animName][idx].weight) do
		roll = roll - animTable[animName][idx].weight
		idx = idx + 1
	end
	local anim = animTable[animName][idx].anim
	
	if (anim ~= currentAnimInstance) then
		
		for _, Object:AnimationTrack in Humanoid.Animator:GetPlayingAnimationTracks() do -- Stops all of the animations under animator, except the one you just played

			if Object == currentAnimTrack then continue end -- check to see if that's your animaton that just played
			Object:Stop(transitionTime)
			Object:Destroy()
			currentAnimTrack = humanoid:LoadAnimation(anim)
		end

		currentAnimSpeed = 1.0

		
		currentAnimTrack.Priority = Enum.AnimationPriority.Core

		currentAnimTrack:Play(transitionTime)
		currentAnim = animName
		currentAnimInstance = anim

		if (currentAnimKeyframeHandler ~= nil) then
			currentAnimKeyframeHandler:disconnect()
		end
		currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)

	end
end

ok rn i found out that tracks were reaching 64 because there were 2 animate scripts at the same time and now i dont understand how to make roblox stop giving my character the second animate script if theres already one in a player

Just so you know parenthesis are not need for if statements in luau. Luau relies on indentation or keywords/line breaks to define the scope and condition, like python.

Ex of indentation to define stuff.

if 1 == 1 and -- This errors because the statements are not on the same index level
1 == 2 
then

end

if 1 == 1 and -- This works because the statements are on the same index level
	1 == 2 
then

end

You also don’t need to write

Variable = Variable + 1

You can just write

Variable += 1
-- This is just saying Variable = Variable + 1

( Roblox has some quality of life features )

Also the function I wrote is just copy and paste into anywhere, but your function. just set the animator to your animator.

Animator.AnimationPlayed:Connect(function(AnimationTrack)

I removed the typecheck stuff, but what this is what it really is saying.

local function MyFunction(AnimationTrack) -- a function 

end

Animator.AnimationPlayed -- This is "fired," when ... happens ( Your animator plays an animation )
-- i.g. a forever loop checking if an animation is played and playing a function when that happens,
-- when the script is ran it creates the "Forever loop".
-- If you put this into a function, when the function is ran it creates a "Forever loop"

:Connect() -- This connects to Animator.AnimationPlayed ( the "Forever loop" ) 
-- when it's "fired" it plays the function inside of the parenthesis
-- Inputs the arguments your "Forever loop" returned into the function

-- i.e Animator.AnimationPlayed returns an AnimationTrack so it inputs that into the function.

:Connect(MyFunction) -- OR
:Connect(Function(Arguments) -- A new function 
end)

It’s kind of unclear, but I hope you understand what I meant.

So basically I’m checking if Animator.AnimationPlayed was “fired,” if it was then I do the function that was inside of the :Connect(), passing on the values that Animator.AnimationPlayed returns to the function.

Remember to name your script exactly ‘Animate’ and put it in StarterCharacterScripts (Inside of starterPlayer) You could also run a script similar to this:

local myAnimateScript = script:WaitForChild("Whatever your script is called")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

player.CharacterAppearanceLoaded:Wait() -- Wait until the character is fully loaded
local animateScript = character:WaitForChild("Animate") -- The default script

animateScript:Destroy() -- Destroy the default script
myAnimateScript.Enabled = true
myAnimateScript.Parent = character

Though, for this to work, your animate script has to be directly under this script AND it has to be disabled. (In Properties uncheck Enabled)