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

ScreenGui is not a valid member of PlayerGui? [SOLVED]

I'm simply defining variables, and this error appears:

ScreenGui is not a valid member of PlayerGui, Line 1

here is the code

local blue = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Blue
local red = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Red
local player = game.Players.LocalPlayer

3 comments

0

Is this a Script or a LocalScript?

0

Localscript

0

Maybe you can try game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.Blue?

2 answers

Sometimes the Script can run faster than the assets can load, try writing this to make sure the Script can slow down for the asset targeted.

It's also best if you define 'player' as a shortcut earlier:)

local player = game:GetService("Players").LocalPlayer --// more efficient way of getting the Local Player.
local playergui = player:FindFirstChild("PlayerGui") --// Shortcutting their Gui, you don't have to do this.
local blue = playergui:WaitForChild("ScreenGui").Frame.Blue --// ':WaitForChild('decendant') will force the Script to wait until the asset exists.'
local blue = playergui:WaitForChild("ScreenGui").Frame.Red --// Same method follows

Hope this was your issue, good luck

1 comment

0

game.Players and game:GetService("Players") are exactly the same thing and make no difference from each other

I fixed it, just had to add "wait(1)" at the top of the script.

1 comment

1

use :WaitForChild("ScreenGui"), not wait(1)

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