When ever I ran a code sometimes it'll say Infinite Yield possible at so on so forth so can someone explain to me what an infinite yield is please. Thanks!
What is an infinite yeild?
2 answers
When you get the warning Infinite yield possible on OBJECT:WaitForChild(NAME), this means that it is possible for the thread to be yielded (or paused) forever. This occurs when you do not use the second argument, the timeout.
Here is an example
local part = game:GetService("Workspace"):WaitForChild("Part", 5);
So this will wait 5 seconds for the child. If it is not found within 5 seconds :WaitForChild() returns nil.
3 comments
Notice that the warning does not propagate. Other than that, you should not worry about the warning.
Thanks
If you don't set a max time limit on the WaitForChild and it remains in an infinite yield state forever, will that cause any sort of lag overtime since I'm assuming it just continuously checks if the Instance exists?
Possible Infinite Yield is caused by WaitForChild having to wait for longer than a few seconds.
This is simply a warning from roblox saying: "Hey, this object might never get created and your script will wait forever". It's ignorable, but if you don't want to see it, you can use the 2nd argument of WFC which is float TimeOut.
Eg. Thing:WaitForChild("Name",10), will wait at most 10 seconds before continuing the script, or less if the object with Name is found. If an instance is not found, it will return nil if assigned to a variable.
You can make this number math.huge so that the warning will never show up, but it could cause some confusion if you don't see why your script isn't running.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Oopsie didnt mean to edit this