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

WaitForChild() doesn't work as intended?

Asked by 6 years ago

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?

0
Infinite yields aren't errors. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

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. SuperMario9595 150 — 6y
0
You're probably waiting too long for an object. User#19524 175 — 6y
0
How would that happen? SuperMario9595 150 — 6y
Ad

Answer this question