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

How do I stop an infinite yield?

I have a script below, declaring my gui variables:

local gui=player:WaitForChild("PlayerGui")
local ui=gui:WaitForChild("ui")

but whenever I run my game, this message appears:

Infinite yield possible on 'Players.RosyCatCLash.PlayerGui:WaitForChild("ui")'

How do I stop that message from appearing?

Thank you

2 answers

The "Infinite yield possible" messages appear when you have a Instance:WaitForChild() without a timeout, which means if an instance with said name isn't there, the script will wait forever. To prevent this and the message, you need to add a timeout, like Instance:WaitForChild("Part", 100). Timeout is in seconds.

Here.. RaforawesomeAlt is very wrong and that causes big amount of lag..

repeat wait() until game:IsLoaded()
local gui=player:WaitForChild("PlayerGui")
local ui=gui:WaitForChild("ui") --// Infinite yield happens if the object was not found or too many objects of the same name were found in the parent. This could also be caused by player not loading in. I recommend using this whole script

2 comments

0

You're wrong. WaitForChild with a timeout has no implicit performance stunts. It just waits until n amount of seconds after yielding. You're just giving him the same code that he posted. Stop being bad.

0

ok

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