Im using a StarterCharacter and this warn appears, is there someway to disable it?
something like:
repeat chartorso = location:WaitForChild("Torso") until chartorso ~= nil
From the documentation on WaitForChild “If a call to this method exceeds 5 seconds without returning, and no timeOut parameter has been specified, a warning will be printed to the output that the thread may yield indefinitely.”
First make sure the instance you are waiting for does eventually exist, and if it does then set the timeout parameter to something longer than 5 seconds.
This wont remove the warning, the warning does not stop the function from yielding, it just alerts you that it may yield forever. This is functionally the same as just doing torso = rig:WaitForChild("Torso)
You can stop the warning by following this pattern in your code:
local child = parent:WaitForChild("ChildName", 5)
if not child then
-- cancel the action, or some other handling
return
end
-- Now you can use the child in some way here
print(child.Name)
It’s recommended to not use WaitForChild without a timeout when the child might not ever exist (which is more than one might think because of edge cases). If the child can never exist, yields like this can potentially go on forever and build up in your game.
There was a resource about this but I can’t find it, here is a quote from buildthomas about it from a while ago:
This technically works if you add a time out (e.g.
... = location:WaitForChild("Torso", 5) until ...
but still has the same problem as using WaitForChild without a timeout in general: the yield can last forever. These can be good and useful though if they include canceling conditions (e.g. the parent is moved to nil, etc).
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.