Animation error, humanoid has to be a descendant of the game object

So I’m creating magic attacks with tools and it works perfectly until you reset/respawn. When you respawn the script throws this error:

22:36:50.620 - LoadAnimation requires the Humanoid object (Fusionet.Humanoid) to be a descendant of the game object

Even thought I wait enough time till my character is fully in the game, it still errors.

Sample of the script (local script inside a tool, which is parented to StarterPack):

tool.Equipped:Connect(function(mouse)
	local startAnimation = humanoid:LoadAnimation(script.Start)
	local endAnimation = humanoid:LoadAnimation(script.End)
end

I tried loading the animation outside the equipped function, but the same thing happens. I’ve seen other post like this on the DevForum, however none of the posts had a solution. The humanoid variable is not an old variable since I tested if the script re-runs every time you respawn, and it does. If anyone has ever encountered this problem your solution would be great, thanks.

Example:

3 Likes

What is the “humanoid” variable? I’m assuming that you are grabbing the humanoid at the start of the script. If this is the case, the problem is that when the player dies, their character gets destroyed (including the humanoid).

This means that when you try to use the tool after the character dies, you are trying to apply an animation to a humanoid that doesn’t exist.

The solution to this problem is to set the “humanoid” variable in the “Equipped” event. That way, you grab the latest humanoid every time they equip the tool.

Hope this helps! If it worked, please don’t forget to give me the solution :smiley:

7 Likes

No response? (30 chars 30 chars)

This is what I used to get the humanoid, and yes it is at the beginning of the script.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

I thought that was the case of it being an old variable from other posts, but how? The script runs every time the character loads in since its in starter pack, so shouldn’t it be updated? And if I were to put it in the equipped function, I would also have to make a new “character” variable since that was the old character.

Edit: I assigned a new character variable and humanoid variable in the Equip function, and It fixed it. But is there another way, I’m still confused? I feel like I’ve been lied to this whole time lol.

That’s actually quite weird. Iirc scripts in StarterPack should be recreated every time the player respawns.

That isn’t a problem performance-wise. Declaring humanoid there should be fine. The old reference will be garbage collected by Lua (if you don’t know what that is, don’t worry about it for now).

1 Like

69.5 years later and I know the Root solution to this problem.

Get the “Animate” script that is automatically placed in your character when you Play the game.

Paste this in Animate script after local Humanoid →
“repeat wait() until Humanoid:IsDescendantOf(game)”

1 Like