How do I make GUI appear by pressing a button?

Hey all! It’s been a while since I have touched scripting but I decided to play around with GUI’s today. Now I’m trying to make a very very very simple UI where if I press a button then it should make another window appear. But for some reason it doesn’t work at all nor does debugging to see if it runs the code at all doesn’t work either.

Maybe I’m doing this entirely wrong but a example or anything would be helpful.

-- Settings GUI
local imageButton = script.Parent

-- Options GUI
getOptions = game:GetService("StarterGui")
getOptions.Options.Frame.Visible = false

local function onMouseClick()
    local optionFrame = getOptions.Options.Frame
	optionFrame.Visible = true
end

imageButton.InputBegan:Connect(onMouseClick)

image_2023-03-09_004257027

I honestly can’t tell if I shouldn’t be doing this sort of thing in StarterGui or it’s a filterenabled sort of issue.

Thank you!

1 Like

Parent the gui into the player’s playergui once you press the button.

4 Likes

I never even knew PlayerGui was even a thing… I should dive more into documentation silly me. But thank you!

1 Like

Use MouseButton1Click instead of InputBegan.

local player = game.Players.LocalPlayer

local imageButton = script.Parent

local options = player.PlayerGui:WaitForChild("Options")
options.Frame.Visible = false

local function onMouseClick()
	local optionFrame = options.Frame
	
	if optionFrame.Visible == false then
		optionFrame.Visible = true
	else
		optionFrame.Visible = false
	end
end

imageButton.MouseButton1Click:Connect(onMouseClick)

Edit: Just noticed that it was already solved. My apologies.

1 Like

I changed to mousebuttonclick because I noticed that hovering over the button counted as an input. But thanks for giving your time to answer :slight_smile:

1 Like

Gah never mind, I made a place, but I was too slow!
Button_thing.rbxl (45.6 KB)

And for the record, no need to do any re-parenting. It all goes to where it is supposed to be on execution, just use correct references when coding, i.e. don’t do half your code using script.Parent to locate stuff and then use a StarterGui to locate the rest. Keep it consistent!

1 Like

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