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

What's an infinite yield, why is this happening?

Asked by
spr_ead 47
5 years ago
local player = game.Players.LocalPlayer
local pgui = player:WaitForChild('PlayerGui')
local sgui = pgui:WaitForChild('songGui')

It happens on line 3, help will be greatly appreciated

2 answers

Log in to vote
2
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

An infinite yield is a warning that warns that you that a script might wait forever to wait for a child that either hasn't loaded in, is non-existent, or is parented somewhere else.

This normally occurs when you use WaitForChild(without the timeOut parameter specified), when WaitForChild exceeds 5 seconds and can't find the GUI, it'll print an infinite yield warning.

A way to avoid this is to specify the timeOut parameter. WaitForChild will wait the amount of seconds in the timeOut parameter, if it can't find the GUI, WaitForChild will return nil.

You should make sure you're searching for the GUI under the correct parent with the correct name

Ad
Log in to vote
1
Answered by
CPF2 406 Moderation Voter
5 years ago
Edited 5 years ago

The script is infinitely yielding on the function :WaitForChild() because songGui isn't a child of the PlayerGui

The :WaitForChild() function yields until it finds the child with the name specified, if it doesn't ever find the child with the name specified, it yields infinitely.

Answer this question