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

Why do i keep getting infinite yield, and why does my script search in Playergui?

So i made this simple localscript for a chassis, inside its plugins folder

local FE = workspace.FilteringEnabled
local F = {}
local DriveSeat = script.Parent.Parent:WaitForChild("DriveSeat")
local car2 = DriveSeat.Parent

if car2.Body.Rogue.Engine.Crash.Disabled == true then
	script.Parent.Parent.IsOn.Value = false
end

All it should do is go to body, the car, the engine mesh part, the crash script and check if its disabled and then go to A-Chassis Interface and disabled the IsOn value. but i keep getting

"Infinite yield possible on 'Players.NICULL897.PlayerGui:WaitForChild("DriveSeat")'" I've been spending the last 2 hours and a half trying to figure out why. i don't know if im missing something obvious or not

1 answer

If a call to the WaitForChild function exceeds 5 seconds without returning the instance you are looking for, and no timeOut parameter has been specified, a warning will be printed to the output that the thread may yield indefinitely; this warning takes the form Infinite yield possible on X:WaitForChild("Y"), where X is the parent name and Y is the child object name.

so basically, the waitforchild function waited more than 5 seconds and can't find what you are looking for and since you didn't add a timeOut parameter, the game thinks it the script will wait forever.

To not get this warning just add a timeOut parameter like this:

X:WaitForChild("Y",1) -- 1 is the timeOut parameter. It means that waitforchild will only wait 1 second at most and if it can't find what you are looking for in 1 second, it will continue the script by returning nil (nothing).

4 comments

0

also, check if driveSeat actually exists.

0

Stuff in StarterGui, automatically goes to your playergui. and everytime you die, staratergui will clone it back to playergui. Including the script that is waiting for "driveSeat" (unless the gui has ResetOnSpawn set to false)

0

Weird, since i looked through other plugins which had the same variable, in the same folder as me and did not get this error. btw there is nothing in starter gui

0

btw, a gui HAS to be in playergui, or else the player will not see the gui at all.

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