How do I make a GUI open/close

Hello! I’m trying to get this GUI to open/close when clicking a button and it just ain’t working what so ever.

local openbutton = game.StarterGui.ScreenGui.Settings.ImageButton
local Gui = game.StarterGui.ScreenGui.SettingsFrame

openbutton.MouseButton1Click:Connect(function()
Gui.Visible = true
if Gui.Visible == true then
Gui.Visible = false
end
end)

9 Likes

Could you show us your script and let us know if it’s a LocalScript or a ServerScript?

1 Like

It’s a local script and everything which is there has been put above.

1 Like

I see the problem, you shouldn’t be controlling the GUI from StarterGUI. Could I see the position of all the objects? Like
image

It needs to be a local script in the button: script.Parent.MouseButton1Click: Connect(function()
script.Parent.YourFrame.Visible = true
end)

3 Likes

You would need to be referring to playerGui the other way.

Here you go!

1 Like

Replace your code with this

local openbutton = script.Parent
local Gui = script.Parent.Parent.Parent

openbutton.MouseButton1Click:Connect(function()
	Gui.Enabled = true
	
	if Gui.Enabled == true then
		Gui.Enabled = false
	end
end)
2 Likes

I want it to only open/close the settingsframe though.

2 Likes
local openbutton = script.Parent
local Gui = script.Parent.Parent.Parent.SettingsFrame

openbutton.MouseButton1Click:Connect(function()
	Gui.Visible = true
	
	if Gui.Visible == true then
		Gui.Visible = false
	end
end)
3 Likes

It justs hides my button and not the frame for it.

2 Likes

Fixed it. Edited the last post.

1 Like

It does not seem to work. Like it ain’t opening the frame or closing it.

2 Likes

Could you show me the developer console?
Press f9 in game after pressing the button

f9 on my pc turns my screen off.

On some computers you have to hold the fn button when pressing f keys

Assuming you’ve parented everything correctly ;

local openbutton = game.StarterGui.ScreenGui.Settings.ImageButton
local Gui = game.StarterGui.ScreenGui.SettingsFrame

openbutton.MouseButton1Click:Connect(function()
 if Gui.Visible == false then
Gui.Visible = true
else if Gui.Visible  == true then
Gui.Visible = false
     end
end)
3 Likes

Thanks that worked! You have been a lot of help lately.

Oof…
18:43:25.367 - Players.tyler09456.PlayerGui.ScreenGui.Settings.ImageButton.LocalScript:6: Expected ‘end’ (to close ‘function’ at line 4), got ‘else’

I can jump back in to studio and fix it if you want too