PlayerGui is not a valid member of players?

I Have made a script that opens a gui for a player once the player clicks on the gui, I Did it in 2 games, in one of them it worked perfectly fine and opened the gui but in the other one it said that PlayerGui is not a valid member of Players.
I Used the same script in both of the games.
The script i used:

script.Parent.MouseClick:Connect(function(player)
	local gui = player.PlayerGui["ShopGui"]
	print(player.Name)
	gui.Enabled = true
	end)
2 Likes

You wrote 2 times end) instead have only one like so:

script.Parent.MouseClick:Connect(function(player)
	local gui = player.PlayerGui["ShopGui"]
	print(player.Name)
	gui.Enabled = true
end)
1 Like

I edited the script i forgot the delete the last end, but it isnt the problem.

Why is your first argument in the MouseButton1Click event called player? You don’t need that argument that’s probably the issue

That argument finds the player but for some reason it doesnt find playergui

image

Would be better to use local player

I am not a professional scripter but this is what I should do:

script.Parent.MouseClick:Connect(function(player)
local gui = game.Players.PlayerGui.ShopGui
print(player.Name)
gui.Enabled = true end)

Maybe wait for it to exist?

script.Parent.MouseClick:Connect(function(player)
	local gui = player:WaitForChild("PlayerGui").ShopGui
	print(player.Name)
	gui.Enabled = true
end)
1 Like

Or use ‘player:WaitForChild(“PlayerGui”)’

@nomcell, its Players.
Not player.

It doesn’t print out the players name nor enables the gui

But it doesnt show any errors at all

Okay what is going with WaitForChild?

Maybe try a convoluted method?

local gui = game.Players[player.Name].PlayerGui.ShopGui

If that doesn’t work etiher,

What type of script is this? Where is it located?

The script is inside a click detector which is in a part, the script is a regular script

So you’re trying to to create a button that opens a GUI? Why don’t you just do

local player = game.Players.LocalPlayer
local gui = — path to GUI

script.Parent.MouseClicl:Connect(function()
GUI.Enabled = true
end)

Sorry I’m on mobile can’t write properly

as i said i tried it in another game and it worked, in this one it shows the same error over and over

MouseButton1Click is an event for GuiButtons, not ClickDetector

@nomcell maybe try rewriting it in an Empty Baseplate to see if it’s somehow an issue with your place?

This is really odd since there was a similar issue like this before where PlayerGui couldn’t be found.

What happens whe nyou try to look inside your player from the server?

2 Likes

Ok so I tried it in a baseplate and it printed my name and worked, and I found the error, there was another script in a gui called “Opening” where it runs a script once the player joins but what exactly disabled player gui in it?


script.Parent.Enabled = true
	script.Parent.Background.BackgroundTransparency = 0
	local randomtext = math.random(1,5)

	script.Parent.Sound:Play()
	wait(0.1)
	script.Parent.TextLabel.Text = "a game made by..."
	wait(5)

	script.Parent.TextLabel.Text = "nomcell"
	wait(1)
	if randomtext == 1 then
		script.Parent.TextLabel.Text = "original content"
	end
	if randomtext == 2 then
		script.Parent.TextLabel.Text = "fnf text reference"
	end
	if randomtext == 3 then
		script.Parent.TextLabel.Text = "dababy or dabibi?"
	end
	if randomtext == 4 then
		script.Parent.TextLabel.Text = "ye i can get freky friday night"
	end
	if randomtext == 5 then
		script.Parent.TextLabel.Text = "kidnapped by Arlel_Dreemurr"
	end
	wait(2)
	script.Parent.TextLabel.Text = "Nomcell's hell"
	script.Parent.TextButton.TextTransparency = 0
	local tw = game:GetService("TweenService")
	local dest = {}
	dest.Position = UDim2.new(0.433, 0, 0.684, 0)
	local tweeninfo1 = TweenInfo.new(1.5,Enum.EasingStyle.Back,Enum.EasingDirection.In,0,false,0)
	local fin = tw:Create(script.Parent.TextButton,tweeninfo1,dest)
fin:Play()

ignore the text its just a meme game

Ther edoesn’t seem to be anything that should disable PlayerGui in that script? What happens whe nyou disable it and try again?