Still have questions? Join our Discord server and get real time help.
2

# What is an infinite yeild?

Edited 1 year ago

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!

0
Oopsie didnt mean to edit this ianbabin 5 — 1y

1

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

lua 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.

0
Notice that the warning does not propagate. Other than that, you should not worry about the warning. User#24403 41 — 1y
0
Thanks ianbabin 5 — 1y
0
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? climethestair 1540 — 1y
0
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.