AnimationTrack limit

So I’m currently trying to create a script to play an animation when the character is idle, walking or running. My current problem is that the script seems to be apparently loading new animations instead of just playing and stopping them. If anyone has any idea or can point out a mistake i might’ve made then feel free.

local idleAnim = humanoid:LoadAnimation(assets.Anims[animtype].Idle) 
local walkAnim = humanoid:LoadAnimation(assets.Anims[animtype].Walk) 
local runAnim = humanoid:LoadAnimation(assets.Anims[animtype].Run)

local function steprender()
	if humanoid.MoveDirection == Vector3.new() then
		if state ~= "Idle" then
			state = "Idle"
			walkAnim:Stop()
			idleAnim:Play()
			runAnim:Stop()
		end
	else
		if humanoid.WalkSpeed > 16 then
			if state ~= "Run" then
				state = "Run"
				walkAnim:Stop()
				idleAnim:Stop()
				runAnim:Play()
			end
		else
			if state ~= "Walk" then
				state = "Walk"
				walkAnim:Play()
				idleAnim:Stop()
				runAnim:Stop()
			end
		end
	end
end

game["Run Service"].Heartbeat:Connect(function()
	steprender()
end)

Some of the script might be missing since this is just an outtake of the main script.

Firstly id try temporarily putting the animations into funtions that return the loaded animation with a print message attached, then using this you can see which animations are doing this. Its likely that its loading every time you call it.

When using animations its best to use preload as this sets it up for repeated use without loading constsntly.

Another thing that might be worth doing is actually setting the animation up as an object as that can help reduce the issues from loading within a script.

Also if you are trying to check every step it might be overiding the current animation thats playing, so make sure to log the previous state and check if its changed before trying to play another animation (if its the same make sure animation hasnt finished)