My local script infinitely yielding for impossible circumstances

My main script that controls the GUI is in StarterPlayerScripts and it keeps yielding the code when i use WaitForChild to get basic stuff inside of PlayerGui:

local PlayerGui = Player:WaitForChild("PlayerGui")
local Gui = PlayerGui:WaitForChild("MainMenu")
local TicketMachine = PlayerGui:WaitForChild("TicketMachine")

I suspect this is something involving the structure of my variables but Im unsure.
image

2 Likes

It’s a bit cheesy but i find that adding the line local character=Player.Character or Player.CharacterAdded:Wait() fixes it, it just makes the script wait till the character is loaded, sometimes it does that when everything takes too long to load so making the script wait until atleast the character is loaded solves that problem

Just to be sure there is no discrepancies, can you please send a screenshot of StarterGui?

Do you happen to have CharacterAutoLoads off? GUIs will not load normally if you have it turned off (it will load with the character though).

maybe because PlayerGui is a data not an object so you don’t have to wait for child.
try this

local PlayerGui = game.Players.LocalPlayer.PlayerGui

image
This is my startergui set up, I believe this issue was happening due to bad wifi at the time. Anywayto fix this for players with bad wifi?

This should at least wait for the GUI to load.

local Character = Player.Character or Player.CharacterAdded:Wait()
local PlayerGui
repeat task.wait()
  PlayerGui = Player.PlayerGui
until PlayerGui ~= nil
local Gui
repeat task.wait()
  Gui = PlayerGui:FindFirstChild("MainMenu")
until Gui ~= nil
local TicketMachine = PlayerGui:WaitForChild("TicketMachine")

can I see your whole script, maybe bc you missed some declare

Im not sure where is that option?

Is ScreenGui.ResetOnSpawn on? Turn it off

1 Like

It’s a property of the Players service.

image