GUI button script not working

What am I trying to do?
I am trying to make a button make a GUI appear once a player presses it.

What is the issue?
Whenever I press the button, the GUI is not showing. I used print() in the function and it registered the click, but the GUI did not appear.

What do I have?

local button = script.Parent
local gui = game.StarterGui.MenuGUI.ProfileFrame -- The GUI I want to appear

button.MouseButton1Click:Connect(function()
	gui.Visible = true
end)

The code is in a LocalScript inside the button.

I would really appreciate it if someone knew how to solve this problem, I have not scripted GUIs that much so it would be very useful!

You need to use the Button under PlayerGui which is where it gets replicated to:

local plr = game.Players.LocalPlayer
local gui = plr:WaitForChild('PlayerGui').MenuGUI.ProfileFrame
4 Likes

I recommend using Button.MouseButton1Down if the button was replicated.

1 Like

I tried using it under PlayerGui but I got the following error message:

MenuGUI is not a valid member of PlayerGui “Players.(player name).PlayerGui”

1 Like

Using script.Parent.Parent etc etc until you get there would probably be the best way to do it.

Use game.Players.LocalPlayer.PlayerGui.MenuGUI.ProfileFrame.Visible = true

Try putting a click detector in the button and then do

local button = script.Parent
local ClickDetector = script.ClickDetector
local gui = game.StarterGui.MenuGUI.ProfileFrame

ClickDetector.MouseButton1Click:Connect(function()
gui.Visible = true
end)
1 Like