Why my DialogGui can't be found?

I have a ScreenGui named “aaaDialogGui” in StarterGui ,and want to use it in my localscript named DialogScript in my StarterPlayerScripts .
image

and the codes are:

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local dialogFrame = playerGui.aaaDialogGui.DialogFrame

But it is wrong and posts the error msg int the output Window:
[18:14:50.464 - aaaDialogGui is not a valid member of PlayerGui]

Why?
I learn from the article:

Thx u all

I think the localscript is being too fast, and everything isn’t loaded in properly.
So what we do is we wait for the ScreenGui using :WaitForChild().

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local dialogFrame = playerGui:WaitForChild("aaaDialogGui").DialogFrame
2 Likes

LocalScripts run after game.Loaded fires, which signifies that the server has finished replicating instances to the client from containers that can be replicated. The contents of “Starter” containers are copied after game.Loaded fires, so the LocalScript doesn’t have implicit access to them unless the LocalScript is a descendant of the LayerCollector.

FTFY.

Everything at the point of a LocalScript’s execution is loaded. There’s no real such thing as “improper loading” (which is a bug) or “LocalScripts running too fast” (which is a lack of accommodation for the order of replication).

1 Like