Glorpia Docs
Scripting / Method

WaitForChild()

Waits until a direct child with the requested name exists, or until an optional timeout expires.

Syntax

instance:WaitForChild(name, timeout?)

Parameters and return value

NameTypeDescription
namestringExact direct-child name to wait for.
timeoutnumber?Optional maximum wait time in seconds.
returnInstance or nilThe matching child. Returns nil when a supplied timeout expires.
Without a timeout, the call yields until the named direct child exists. It does not search descendants.

Example: Wait For A Character Part

Luau
local character = script.Parent
local root = character:WaitForChild("HumanoidRootPart")

print(root.Position)

Example: Use A Timeout

Luau
local optionalPart = workspace:WaitForChild("RoundStart", 5)

if optionalPart then
    print("RoundStart is ready")
else
    warn("RoundStart did not appear within 5 seconds")
end

Related