New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

What is an infinite yeild?

Asked by 8 months ago
Edited 8 months 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 — 8mo

2 answers

Log in to vote
1
Answered by 8 months ago

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 5 — 8mo
0
Thanks ianbabin 5 — 8mo
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 1491 — 8mo
Ad
Log in to vote
0
Answered by
RubenKan 3525 Moderation Voter Administrator Community Moderator
8 months ago
Edited 8 months ago

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.

Answer this question