Can't access ScreenGui with script

I’m trying to access ScreenGui but I can’t because when I do it says it can’t find PlayerGui.
I tried using findfirstchild to get it but as far as I know I can’t access any of it’s children after I use find first child. If I put a thing with findfirstchild in a variable then the varible returns nil.

local GUI = script.Parent.Parent.PlayerGui.ScreenGui


Can you show me a screen shot of where it is so I can understand better?

have you tried WaitForChild()

local player = script.Parent.Parent
local GUI = player.PlayerGui:WaitForChild('ScreenGui')

Also you can’t really print a gui

image – first screenshot: output
image – second screenshot: player folder.

Yep i forgot to say it is in starter playerscripts. The point of it is to make boot_up_screen visible (will get rid of the print thing later) I did but i cant figure out how to go to a child of the thing that i use wait for child on.

I edited my reply with some code showing you how to use WaitForChild

You can actually print an instance, I just tested this out.

And for the problem at hand, try using :WaitForChild() for the ScreenGui.

1 Like

Try adding an delay before you can reference the ScreenGui:

wait(math.random(1, 3))
local GUI = script.Parent.Parent.PlayerGui.ScreenGui


math.random was just random xd, bad joke…I think this code will work?

What it prints?The class?

[30 char]

You literally just said the exact thing I did

It just prints the name of the instance.

You said that it isn’t possible to print instances, whereas I said that it was possible.

Edit: I know what you mean now, you were talking about the :WaitForChild() thing. In that case, yes, I did happen to say the same thing you did.

I was just printing it as a test. The main issue is that i cant figure out how to instance more things after :WaitForChild()

Make a variable for it and call each child from that variable


local player = script.Parent.Parent
local GUI = player.PlayerGui:WaitForChild('ScreenGui')

local frame = GUI.frame
local textbox = GUI.textbox
local label = GUI.textlabel

Due to an oversight on roblox’s end, (which they haven’t fixed yet). LocalScripts in StarterPlayer and StarterCharacterScripts do not instantly have their children instances when they start running, the way around this is by using WaitForChild(), this will hold the code indefinitely until it can find the object

If you get a warning along the lines of Possible Infinite Yield on WaitForChild("GUI"), the object probably doesn’t exist


Is it a script or localscript? It should be a localscript to refer to GUIs

yes the script is a local script

The issue is that scripts that are in StarterPlayerScripts are ran before the PlayerGui exists, you should probably look into WaitForChild()

An example of what this would look like is

local GUI = script.Parent.Parent:WaitForChild("PlayerGui"):WaitForChild("StarterGui")

Since your GUI is inserted when a player is added and the GUI has ResetOnSpawn turned on, you’ll probably need to write an event handle like this

local GUI = LocalPlayer.PlayerGui:FindFirstChild("ScreenGui") --fetch the GUI if it already exists

LocalPlayer.CharacterAdded:Connect(function() --Local Player CharacterAdded event handle
   GUI = LocalPlayer.PlayerGui:WaitForChild("ScreenGui") --Set the GUI variable to the new GUI

You could try:

local player = game.Players.LocalPlayer
local GUI = player:WaitForChild('PlayerGui'):WaitForChild('ScreenGui')

In the case you get the “infinite yield possible” warning, you could replace line 2 with

local GUI = player:WaitForChild('PlayerGui'):WaitForChild('ScreenGui', math.huge)

Additionally, you could make sure the game is fully loaded before you index the gui.

local player = game.Players.LocalPlayer
local GUI = player:WaitForChild('PlayerGui'):WaitForChild('ScreenGui', math.huge)


Wait you can do more than 1 wait for child? Thats awesome! :smiley:

Feel like I should note repeat wait() until game:IsLoaded() is redundant, you can just use game.Loaded:Wait()