If I have a Script
or LocalScript
in StarterCharacterScripts
, should I use script.Parent:WaitForChild("Humanoid")
or is using script.Parent.Humanoid
safe? Also when is Humanoid.RootPart
set?
No… no no no no… ALWAYS use :WaitForChild("Humanoid")
… an even safer way to check if the players character has loaded is :CharacterAppearanceLoaded()
. This event will fire when the player’s character has FULLY loaded.
Unless you know the player CAN’T die at the time, and they’ve SURELY already loaded, you should always use it.
also, it’s character.humanoidrootpart, not humanoid.rootpart.
It’s both, Humanoid.RootPart
property should lead to the Instance/Child which is Character.HumanoidRootPart
It’s not guaranteed, you should yield using WaitForChild
for the child to replicate.
You never really should be relying on order for systems that you don’t have any control over, including engine replication, you’ll be setting yourself up to run into race conditions. Use appropriate yielding patterns to wait for the instances you need before allowing your code to continue and use those instances.
As of right now it is not safe to directly index any child of the character because there’s no guarantee they will exist. CharacterAdded fires before the character is even fully constructed. There’s a backlogged fix that changes CharacterAdded to fire after the character has been constructed, no outline on when it’ll get shipped unfortunately.