Are Scripts in StarterGUI Ran Before being put into PlayerGUI?

Simple as the title, are scripts in StartGUI ran even before its put into a PlayerGUI?

I am having a issue/an encounter where scripts in StarterGUI are running before being put into a player similar to ServerScriptService, I thought scripts in StarterGUI Dont do anything similar to ReplicatedStorage.

They are not,

-- game.StarterGui.LocalScript
print(script.Parent.Name) -- Returns PlayerGui

Thats weird because I am currently running into the issue that scripts are running in StarterGUI, I have it do the following

print(script.Parent.Parent)

In which I am receiving

PlayerGui 
StarterGui

image
image

Anyway to fix this? Is this normal? I’ve never encountered this before.

Update;
Not sure if this helps anyone,

I tried recreating this with another ScreenGui and putting a script unedited print("Hello World") and only received one Hello World which is from my player being loaded.

I tried copying and pasting all of my stuff in the new ScreenGui and then encountered the same problem as before.

Any script that is placed in StarterGui is parented to a player who joins PlayerGui, so if you did,

print(script.Parent.Parent)

It would return your username since it is the players PlayerGui

To clarify, My script is running before its even put into a player or before a player even joins which I don’t believe is normal?

For example, if I hit the Run testing mode, it still prints StarterGui.

1 Like

No it isnt could you take a screenshot of what the starterGui looks like?

Ohhh, since no player is there it runs in the StarterGui.

This is fixable if you run it normally with just Play.

Thats what i’ve been doing, ill send a video, I was just using Run to see if it’ll still have this issue.
Video of “Play” test:


Video of “Run” test:

The server script loads before the player can join the game so it returns the StarterGui

I think my PC is fast enough to load the game before the script loads.

This can be fixed by adding this at the beginning.

repeat wait() until game:IsLoaded()

woops wrong loaded

Well two issues with this,

  1. game.Loaded only works on LocalScripts (for the giggles I still tried it and didn’t get any print statements meaning it was stuck in a loop.)
  2. I believe if this was the issue, it would only print the 3 things once as only one script would be loaded because the player didn’t respawn or anything, just the initial spawn, not sure if I explained that correctly.

Huh, i guess the only way to check if the game is loaded is too check if the player is there.

repeat wait() until script.Parent.Parent:IsA(“Player”)

1 Like

It happens when your Script has its RunContext set to Server, to fix it just switch it to Legacy. However you should not place any server scripts into StarterGui (unless they check if their parent is the player?).

1 Like

Thank you so much! I forgot I changed that yesterday to test some stuff.

Thanks for your help as well, really appreciated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.