Animation is not loading through the API reference's code

If you are confused, let me explain. I was trying to overwrite the default walk animations to my own walk animation which I have here: Pillow fight run - Roblox

The animation here has an asset id and can be previewed just fine but when I use the API reference script to overwrite it here:

local Players = game:GetService("Players")

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")

	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop()
	end

	local animateScript = character:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = "rbxassetid://7124613658"        -- Run (My animation)
	animateScript.walk.WalkAnim.AnimationId = "rbxassetid://616168032"      -- Walk
	animateScript.jump.JumpAnim.AnimationId = "rbxassetid://616161997"      -- Jump
	animateScript.idle.Animation1.AnimationId = "rbxassetid://616158929"    -- Idle (Variation 1)
	animateScript.idle.Animation2.AnimationId = "rbxassetid://616160636"    -- Idle (Variation 2)
	animateScript.fall.FallAnim.AnimationId = "rbxassetid://616157476"      -- Fall
	animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://616156119"    -- Climb
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)

I noticed that most of the code is deprecated and cannot be used. I can’t find an alternative and have tried to update it to this:

local Players = game:GetService("Players")

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")

	for _, playingTracks in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do -- First change
		playingTracks:Stop()
	end

	local animateScript = character:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = "rbxassetid://7124613658"        -- Run (My animation)
	animateScript.walk.WalkAnim.AnimationId = "rbxassetid://616168032"      -- Walk
	animateScript.jump.JumpAnim.AnimationId = "rbxassetid://616161997"      -- Jump
	animateScript.idle.Animation1.AnimationId = "rbxassetid://616158929"    -- Idle (Variation 1)
	animateScript.idle.Animation2.AnimationId = "rbxassetid://616160636"    -- Idle (Variation 2)
	animateScript.fall.FallAnim.AnimationId = "rbxassetid://616157476"      -- Fall
	animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://616156119"    -- Climb
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded) -- Second change
end

Players.PlayerAdded:Connect(onPlayerAdded)

But still get this result:

If there are any fixes or alternatives to this, I would really appreciate them.

Usually when the animations don’t play at all, it’s either: the user doesn’t own the animations, the rig is different than the one used in the animate script, the animations use a different rig than the rig used in-game, there is an error in the actual animate script. Have you checked for errors or yields?

As far as I know, there are no errors being returned or yields. The only thing that has changed in the script was the asset id and i doubt that causes ALL the animations to break and the animation was made by me using an r6 rig. The only problem that I can think of is the API script being fundamentally broken which is why I’m also asking for alternatives.

Try disabling the animate script and re-enable it after 0.1 seconds, that way it should reload.

Do you think adding a wait(1) or something like that would work?

Might be, try tweaking it a bit and see if anything changes.

I tested the animation itself and it works fine so that’s not the problem. I added the wait(3) function and it didn’t work. The animations aren’t broken now, the script just doesn’t do anything.

Maybe try adding some prints to debug it? I usually do that to check which parts of a script broke.

I found the solution. Turns out that the formatting of the code was really bad so I changed it and tweaked it. Here it is if anyone has the same issue:

local Players = game:GetService("Players")
local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")

	for _, playingTracks in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do -- First change
		playingTracks:Stop()
	end

	local animateScript = character:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = "rbxassetid://7124613658"        -- Run (My animation)
	animateScript.walk.WalkAnim.AnimationId = "rbxassetid://7124613658"      -- Walk
	animateScript.jump.JumpAnim.AnimationId = "rbxassetid://616161997"      -- Jump
	animateScript.idle.Animation1.AnimationId = "rbxassetid://616158929"    -- Idle (Variation 1)
	animateScript.idle.Animation2.AnimationId = "rbxassetid://616160636"    -- Idle (Variation 2)
	animateScript.fall.FallAnim.AnimationId = "rbxassetid://616157476"      -- Fall
	animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://616156119"    -- Climb
end

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(onCharacterAdded) -- Second change
end)

1 Like

What changes from the first version? They look almost identical to me, except the onPlayerAdded function was removed. But either way, good job on finding the solution.

It was really similar. It’s just roblox’s API needing updates.

Alright. Also I suggest you to mark your post as solution so other people with the same problem can easily find the answer. :+1:

1 Like

I put it there for that reason. I forgot to do it though.