HumanoidRootPart missing from Character

I have a local script that runs on a loop that checks distances using HumanoidRootPart.CFrame, but randomly I just get an error saying HumanoidRootPart is not a valid member of (character).

Why does the character exist but not the HumanoidRootPart and in what point of the character lifecycle does this occur? Is it when the character is spawning in or when their despawning?

To fix this error should I use waitforchild, or wait until characteradded is called.

I decided to fix this by just checking if it exists, and if not then continue on to next player, but in situations where I am fine with yielding for it I will just use WaitForChild.

I can’t help you without your code. Can I see your code please?

Check if there’s a ‘HumanoudRootPart’ in the character first

if character:FindFirstChild('HumanoidRootPart') then
    --check distance
1 Like

Hmm… it might be because of the character not being loaded.
Try defining the character like this:

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.Characteradded:Wait()
1 Like

You should use both. The character is assigned to Player.Character before its actual appearance is loaded — so the appearance (basically everything within the character, including the root part) is not immediately added.
You can use CharacterAppearanceLoaded (on the server, this isn’t an option for localscripts) or wait for the root part to be loaded when the character is added.

local char = game.Players.LocalPlayer.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
--// server scripts only
local char = player.CharacterAppearanceLoaded:Wait()
local hrp = char.HumanoidRootPart
1 Like
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character.ChildAdded:Connect(function() -- When something gets parented to the character, it will fire this function
		local success, errormessage = pcall(function() -- If the the object that got added to the player isn't a HumanoidRootPart, no error will appear in the output
			character:FindFirstChild("HumanoidRootPart") -- checks if a HumanoidRootPart was added to the character

Maybe you were calling the HumanoidRootPart before it was even added to the character. Replace the code that you used to get the HumanoidRootPart with this code instead.