(SOLVED) How to make button gui open and close when pressing the same button

Maybe the more verbose version would be better for @DuckKing_FRS to understand it.

1 Like

Yes, that would work. just parent the script to the ScreenGui itself, and not the button.
And then instead of doing
script.Parent.MouseButton1Click ,
do
Script.Parent.account_box.MouseButton1Click

local switch = true
script.Parent.MouseButton1Up:Connect(function()
    if switch then
        game.StarterGui.ScreenGui.Frame.Visible = true
        switch = false
    else
        game.StarterGui.ScreenGui.Frame.Visible = false
        switch = true
    end
end)
local Frame = game.StarterGui.ScreenGui.Frame.Visible
script.Parent.MouseButton1Click:Connect(function()
if Frame.Visible == true then
  Frame.Visible = false
else
	Frame.Visible = true
end
	
end)

Heres a video of me setting up what i think you want, and what im trying to describe.

4 Likes

image
heres what i have i just dont know how to unlock mouse so i can press it cuz my game is first person

change the
image
to be just an
else

i tried your code but i just gave me error
image

you are missing a ) after the last end

end)

You have to make sure all your boxes are named the same otherwise there isn’t a parent/ making it not work.

You can unlock the mouse by either editing the MouseBehavior with UserInputService, or you can create an invisible button with the Modal property

This is probably you’re fastest and best way to do it if I’m going to be honest with you @DuckKing_FRS

how can i put that into a script with enum keycode?

image

local uis = game:GetService("UserInputService")--get the service
--do note that this is detecting if you're pressing a key rather than pushing
--a screen gui button, for you can't click a screengui button if you're in 
--first person
local frame = script.Parent.Frame
uis.InputBegan:Connect(function(input, gpe)
	if input.KeyCode == Enum.KeyCode.Q then --Q is an examble key 
	if frame.Visible == false then
		frame.Visible = true
	else
		frame.Visible = false
		end
		end
end)
1 Like

what do i use local script or script

and i need it to work with first person

Frame.Visible = not Frame.Visible

  1. Make sure your Button isn’t parented to the Frame

Capture d’écran 2022-08-26 211122 DO NOT DO THIS

Capture d’écran 2022-08-26 211148 DO THIS

  1. Add a LOCALSCRIPT inside of your Button

Capture d’écran 2022-08-26 211249 NOT A SCRIPT, A LOCALSCRIPT

  1. In this LocalScript you want to type in this code :
script.Parent.MouseButton1Click:Connect(function() -- Whenever the button gets clicked
	if script.Parent.Parent.Frame.Visible == false then -- If the frame's visibility = false then
		script.Parent.Parent.Frame.Visible = true -- ...we are setting it to true
	else -- If it's not = false (So it's = true)
		script.Parent.Parent.Frame.Visible = false --..we are setting it to false
	end
end)
  1. !!! Make sure, before testing you set the Visibility of the Frame to “False”.
  2. Join the game and it should work.
2 Likes

You should use a LocalScript : How to make button gui open and close when pressing the same button - #30 by nonobest200