"Gui is not a valid member of PlayerGui "Players.kdopdaux1803.PlayerGui""

Hello guys, I have another issue, while doing the update from Button Simulator (As you know, my game.).

This time it’s literally super weird that’s not a valid member.

Even though it says that it’s a ScreenGui, it’s still throwing me an error:

LocalScript inside of the Menu and inside of the MenuFrame:

local Players = game.Players
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Gui = PlayerGui.Gui
local ScreenGui:ScreenGui = PlayerGui.ScreenGui

script.Parent.Parent.Enabled = true

if script.Parent.Parent.Enabled == false then
	ScreenGui.Enabled = true
	Gui.Enabled = true
else
	ScreenGui.Enabled = false
	Gui.Enabled = false
end

I tried everything, changing the script, making :ScreenGui on it adding locals, and no, it didn’t worked.

(Yes I’m sorry to say, even though the topic is closed and been solved and saying it very lately.) I do not want to put :WaitForChild, once I’ve put that, it seems like it worked perfectly fine.

So yeah guys any help is appreciated.

1 Like

Maybe try :WaitForChild, to ensure the ui exists.

1 Like
local Gui = PlayerGui:WaitForChild("Gui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")

If it doesn’t already exist then there’s probably an error somewhere else
Also your error was on line 4, meaning it never reached the ScreenGui.

1 Like

As @GuySalami mentioned, try WaitForChild() instead of just dots. If you dont know, WaitForChild() yields the script until it founds needed instance

1 Like

WaitForChild() you should try that, try doing the part in line 4 like that.

1 Like

Can we have a picture of what’s inside the GUI in the explorer?

1 Like

@ThunderDEV01, @CoffeeEnjoyerr, @GuySalami, @luvreiiko, I don’t want to put :WaitForChild, because it’ll be too easy, I want to make a script, without the :WaitForChild but still works.

@bigfart_mp4, Sure here it is, also, it’s not on the StarterGui:

bandicam 2022-11-07 18-18-45-582

it’s because the script is running before the game is loaded.

local Players = game.Players
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
wait(0.1)
local Gui = PlayerGui.Gui
local ScreenGui:ScreenGui = PlayerGui.ScreenGui

script.Parent.Parent.Enabled = true

if script.Parent.Parent.Enabled == false then
ScreenGui.Enabled = true
Gui.Enabled = true
else
ScreenGui.Enabled = false
Gui.Enabled = false
end

1 Like
local Players = game.Players
local Player = Players.LocalPlayer
local PlayerGui = Player.WaitForChild("PlayerGui")
local Gui = PlayerGui:WaitForChild("Gui")
local ScreenGui:ScreenGui = PlayerGui.ScreenGui

script.Parent.Parent.Enabled = true

if script.Parent.Parent.Enabled == false then
	ScreenGui.Enabled = true
	Gui.Enabled = true
else
	ScreenGui.Enabled = false
	Gui.Enabled = false
end

I’m not sure that this script will work, but I at least suggest you to try it out at least once.

then try to add game.Loaded:Wait() somewhere at the start of the script. It will yield the script until the game is fully loaded

1 Like

I’m sorry, what do you mean by, too easy?

3 Likes

Isn’t making it easy kind of the point…?
There’s not really a reason to make it more complicated than it should be, :WaitForChild is completely fine to use even for people that have coded for years.

2 Likes

Too easy to fix.

This text will be blurred

1 Like

Thanks, this helped me, adding a little wait worked.

1 Like

I know you found a solution, but what do you mean by:

1 Like

Too easy to fix the issue that I had.

Edit: The issue is fixed.

1 Like

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