Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

WaitForChild() doesn't work as intended?

There's a very odd thing going on in my game right now.

Whenever I use WaitForChild() it produces this error: Infinite yield possible in [Location]:WaitForChild([Thing])

but I replace the WaitForChild() with this line of code:

repeat wait() until [Location]:FindFirstChild([Thing])

and it suddenly works. Shouldn't WaitForChild() do the exact thing my workaround is doing? Why is it making this error?

1 comment

0

Infinite yields aren't errors.

1 answer

###An infinite yield is not an error, it's a warning. Warnings are displayed in a yellow/orange text, whilst errors print in red. The "infinite yield" basically means that you didn't use the second argument of WaitForChild, and that the script will yield indefinitely until the child is found. This can cause scripts to break (it has happened to me before). However, this wont be a problem unless it waits too long for an object. Hope I cleared things up.

3 comments

0

That makes sense, but in that case why wouldn't the workaround loop infinitely as well as the WaitForChild? When I use the repeat loop, it passes right away, but the WaitForChild() yields forever.

0

You're probably waiting too long for an object.

0

How would that happen?

This discussion is preserved as it was. New answers, comments, and votes are closed.