Infinite yield possible on 'Workspace:WaitForChild("Part")'in Roblox Luau: what it means and how to fix it
What it means
WaitForChild has been waiting for more than five seconds and the child still does not exist. This is a warning, but the script stays paused on that line until the child appears, which may be never.
The same warning also shows up as:
- Infinite yield possible on 'ReplicatedStorage:WaitForChild("RemoteEvent")'
The smallest script that triggers it
-- The part in Workspace is named "SpawnPart"
local part = workspace:WaitForChild("Part")
print(part.Name)
The fix
local part = workspace:WaitForChild("SpawnPart", 10)
if part then
print(part.Name)
else
warn("SpawnPart never appeared")
end
The name now matches the real object, and the second argument is a timeout: after 10 seconds WaitForChild returns nil and the script carries on.
Common causes
- The name passed to WaitForChild does not match the object's name exactly.
- The object is somewhere else, for example a LocalScript waiting for something that only exists in ServerStorage.
- The object was destroyed, or it is never created because the script that makes it stopped with an error.
Practice this until it sticks
A Deep Dive on WaitForChild and FindFirstChild: 5-minute lessons, each with a quiz. What you miss comes back in the next module. One Deep Dive a day is free. No card.