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

[SOLVED!] Why does it return "ScreenGui is not a valid member of PlayerGui"?

Please, help me! I'm making a new game, and i made a script to change player Gui (LocalScript) so for me,

game.StarterGui.ScreenGui.something.Text = ...

didn't work. So i did

game.Players.LocalPlayer.PlayerGui.ScreenGui.something.Text = ...

of course I didn't make a script to change Text of "something" but that's just a similliar example. Well, the second one usually works. But sometimes it returns

ScreenGui is not a valid member of PlayerGui

error. Well, From what I know- it means that when the script was executed, then PlayerGui didn't have "screengui" inside it-yet. I guess it's because PlayerGui didn't fully load. Of course, in playtest it works all the time, because the player loads instantly with the server. But in the studio server test (in studio>test>local server start) the server loads first, and then the Player loads, so it may be because of this. Game script is a server script of course, while i used LocalScript just for GUI changing. Just in answer, do an example code on how to change exampletext's Text value to something (locally, not from server). Well, this way to make it works even if the Player loads later than the server does. Does anyone understand me?

3 comments

0

hello i hope you see this:

0

Well you forgot that does ScreenGui exists in the PlayerGui? Make sure you put the ScreenGui in the PlayerGui with a script, if not. The error will say that, it means you want to do something on PlayerGui but does not have a child named ScreenGui

0

I have fixed this, but thanks for help anyway!

1 answer

I fixed this! I used Instance:WaitForChild() scripts. You don't need to answer that! Just did:

a = game.Players.LocalPlayer:WaitForChild("PlayerGui")
b = a:WaitForChild("ScreenGui")
b.sometext.Text = "..."

works fine now!

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