Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

What is an infinite yeild?

Asked by
xf8d 5
5 years ago
Edited 5 years 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 xf8d 5 — 5y

2 answers

Log in to vote
1
Answered by 5 years 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 69 — 5y
0
Thanks xf8d 5 — 5y
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 1663 — 5y
Ad
Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years ago
Edited 5 years 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