Humanoid is not a descendant of DataModel

I have a local script in a tool that gets the character from a player like this:

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

However, upon respawning, the code errors with a statement saying Humanoid must be a descendant of DataModel. Is this a bug? Why would the old Humanoid reference stay without being replaced in the local script?

I’ve had a similar issue regarding this as well…

A solution I came up with is forcefully waiting for the humanoid to be existent, using similar code like…

local humanoid
repeat
game["Run Service"].Stepped:Wait()
humanoid = player.Character:FindFirstChild("Humanoid")
until (humanoid and humanoid.Parent)

Another thing you could do, it might not be the most effective thing as ROBLOX could always changed how the systems in that regard operate is do

character = workspace:WaitForChild(player.Name)

Like I said it’s not the most effective of strategies but it should work none the less.

1 Like

To prevent the loop from running iterations when not necessary, you can change to an event-based approach that uses the Humanoid’s existence and descendance as the condition and an event to prevent another iteration from running until a change is flagged. Also, while over repeat: the latter runs at least one iteration due to checking the condition after an iteration, while does it before.

The thing is that the Humanoid will exist if you just use WaitForChild but because of the current avatar loading events order that will not see a fix for some time (but it is planned), you have to check when the character model and by extension, the Humanoid, get parented to the workspace.

local humanoid = player.Character:WaitForChild("Humanoid")

while humanoid and not humanoid:IsDescendantOf(workspace) do
    humanoid.AncestryChanged:Wait()
end

tl;dr Humanoid does exist, parent is not guaranteed though.

5 Likes

This seems most effective so I will check it out soon and mark a solution if it works.

1 Like