Animation "LoadAnimation requires the humanoid object to be a descendant of the game object" error happening when ingame but not in studio

You can write your topic however you want, but you need to answer these question
2. What is the issue? Include screenshots / videos if possible!
My animation isn’t working ingame, and is giving a “LoadAnimation requires the humanoid object to be a descendant of the game object” error, but it works perfectly fine and has no problems whatsoever in studio.
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked up stuff but nothing seems to help since all of their issues happen in studio as well.

local animator = game.Players.LocalPlayer.Character.Humanoid:WaitForChild("Animator")
local holdinganimation = animator:LoadAnimation(Tool.Holding)
Tool.Equipped:Connect(function()
	holdinganimation:Play()
end)
Tool.Unequipped:Connect(function()
	holdinganimation:Stop()
end)

Most likely the character humanoid isn’t loaded yet. I would do a WaitForChild on humanoid also.

1 Like

I changed it, and it’s still giving the same error on the loadanimation line

Can you send your new verison?

Can you submit an image of the Tool’s hierarchy?

local character = Players.LocalPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local holdinganimation = animator:LoadAnimation(Tool.Holding)
Tool.Equipped:Connect(function()
holdinganimation:Play()
end)
Tool.Unequipped:Connect(function()
holdinganimation:Stop()
end)

I also found this post from 2016 that might help?

1 Like

what do you mean by tool hierarchy?

Something like this:
Tool
I want to see all his descendants.

See @Vain_p Reply!

He posted a similiar thread that contains a good answer, check if it isn’t exactly what you need.

1 Like

image

its in client

Where is Holding?
Maybe that’s the problem.

holding is the animation im trying to play

I know, but where is it?
It says it’s inside the tool, but nope.

Your problem is probably that the character variable has a parent property of a nil value at the beginning of the game so it’s still nil while the script tries to get the humanoid which means that the game thinks that the humanoid is not in the game. Have you tried redefining the character variable once you equip the tool? Sometimes studio won’t pick up these kinds of things like a game server would.

2 Likes

Both @Vain_p and @Isaque232 replies should cover the issue. The character isn’t parented at the time of loading the animation.

1 Like

I don’t know why the error, but this works:

local Players = game:GetService("Players")
Player = Players.LocalPlayer
character = Player.Character or Player.CharacterAdded:Wait()
humanoid = character:WaitForChild("Humanoid")
animator = humanoid:WaitForChild("Animator")
local holdinganimation = animator:LoadAnimation(script.Holding)
Tool = script.Parent

Tool.Equipped:Connect(function()
    holdinganimation:Play()
end)
Tool.Unequipped:Connect(function()
    holdinganimation:Stop()
end)

Move the animation within the script.