PlayerGui is a nil

Hello, I’ve tried to make something simple as a localplayer script. I tried all solutions that I had in my mind but none of them worked. I even tried checking on the dev hub didn’t find any solutions either or didn’t read carefully.

I have no idea what’s wrong with this thing but:

this is my code:
script.Parent.Mousebutton1Click:Connect(function()
game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
end

Also this might be wrong category, I got confused between Code review and scripting support.
Yeah, right this is a button. But it seemed not to work?

Is it a LocalScript, and can you post the exact error message thrown.

You should use :WaitForChild()

script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui.Enabled=true
end)

It probably said attempt to call a nil value with PlayerGui, if it’s a server script, that’s because you can’t use LocalPlayer to get a player from the server. To the server, there is no “local player”!!! To a local script there is, because it automatically knows that the local Player is the player it’s descended from, and if it’s not descended from a player i.e. directly parented to the workspace, it would just not run at all. at least that’s my understanding of it, someone mini-roast me if I’m wrong.

No you were right to post it here, scripting support is where you go if you’re having problems with a script (it’s erroring, not doing what it’s meant to etc.)

It’s MouseButton1Click (The b is capitalized). I’m pretty sure events always make the first letter of every word uppercase.

1 Like

Can you show us the exact error message so we can find out what seems to be the problem?