Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to check if the variable has loaded?

I want to get the humanoid of the player, but how do I make the script wait for the player to load?

local player = game:GetService("Players").LocalPlayer
wait(player) -- will this work?
local humanoid = player.Character.Humanoid

2 answers

why do you want to wait if the player gets loaded? The local script only starts if the player is loaded.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

This snippet of code will use player.Character, but if that's nil (not loaded yet), it'll wait until CharacterAdded fires.

KochbananemitGuave is wrong, LocalScripts run when the player is in the game, not the character loaded.

(Note that CharacterAdded doesn't always mean everything in the character is loaded, you may still need WaitForChild).

This discussion is preserved as it was. New answers, comments, and votes are closed.