Custom Animation not working on custom character

So I have a pretty basic custom animation that only works when I don’t have a custom character in. I’ve been looking for other situations like this but none of the solutions have helped.

Animation script (server script inside of server script service)

local function loadAnims(char)
	
	local hum = char:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")
	
	for i, track in pairs(animator:GetPlayingAnimationTracks()) do
		
		track:Stop(0)
		
	end
	
	local animScript = char:WaitForChild("Animate")
	
	animScript.run.RunAnim.AnimationId = "rbxassetid://18254184385"
	
	
	--r6 
	--animScript.walk.WalkAnim.AnimationId = "rbxassetid://18235815773"
	
end

local function OnPlayerAdded(player)
	
	player.CharacterAppearanceLoaded:Connect(loadAnims)
	
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)

any help would be greatly appreciated, thanks!

1 Like

My current debate would be that the humanoid or the animator was not found at the start.

so to easily fix this you can do it like this:

local function loadAnims(char)
	local hum = char:FindFirstChild("Humanoid") == nil and loadAnims(char) or char:FindFirstChild("Humanoid") 
	
    local animator = hum:FindFirstChild("Animator")
	
	for i, track in pairs(animator:GetPlayingAnimationTracks()) do
		track:Stop(0)
	end
	
	local animScript = char:WaitForChild("Animate")
	animScript.run.RunAnim.AnimationId = "rbxassetid://18254184385"
	
	--r6 
	--animScript.walk.WalkAnim.AnimationId = "rbxassetid://18235815773"
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(loadAnims)
end)

I assume you implemented the r6. otherwise you can add this:

local function IsR6Char(char)
    if char:FindFirstChild("UpperTorso") then
        return false
    else
        return true
    end
end

and just add this in the loadanims

local ischr = IsR6Char(char)

if ischr then
    animScript.run.RunAnim.AnimationId = "rbxassetid://18235815773"
else
    animScript.run.RunAnim.AnimationId = "rbxassetid://18254184385"
end

hope it works, also always check the output for errors.

1 Like

Wowwww this works perfect! Thank you so so so so much!

it works cause i waited for the actual CHARACTER to be added. and made a check on the humanoid if it’s nil it will do a recursive on the function otherwise it will use the humanoid if it isnt nil

1 Like