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

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