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