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
| Name | Type | Description |
|---|---|---|
name | string | Exact direct-child name to wait for. |
timeout | number? | Optional maximum wait time in seconds. |
return | Instance or nil | The 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