#How to make a KeyCode both open and close a GUI

1 messages · Page 1 of 1 (latest)

snow bay
#

hi!! ive been trying to make a gui that opens with "e", and closes with "e". with this code ive made so far, ive been able to get it to open with "e", but not to close the key is pressed again. any help would be appreciated!!

local debounce = false
local GUI = script.Parent
local uis = game:GetService("UserInputService")
GUI.Visible = false
local GUIOpenKeyCode = Enum.KeyCode.E
uis.InputBegan:Connect(function(input)
if input.KeyCode == GUIOpenKeyCode then
GUI.Visible = true
end
end)

uis.InputBegan:Connect(function(input)
if input.KeyCode == GUIOpenKeyCode then
if not debounce then
debounce = true
wait(2)
end
end
end)

local GUICloseKeyCode = Enum.KeyCode.E
uis.InputBegan:Connect(function(input)
if input.KeyCode == GUICloseKeyCode then
GUI.Visible = false
end
end)

quiet crane
#

make a variable which changes if E is pressed

#

if variable is false open if its true close

#

or the other way around same thing

snow bay
#

what would i make the variable equal to?

hardy fossil
#

sec

snow bay
shell marlinBOT
#

studio** You are now Level 1! **studio

hardy fossil
#

soo

#

oh wait

#
local GUI = script.Parent
local uis = game:GetService("UserInputService")

local debounce = false

GUI.Visible = false
local GUIOpenKeyCode = Enum.KeyCode.E

uis.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    
    if input.KeyCode == GUIOpenKeyCode and not debounce then
        debounce = true
        
        GUI.Visible = not GUI.Visible
        
        task.wait(2)
        
        debounce = false
    end
end)
#

so

#

every time you press E it sets .Visible to opposite value

#

true to false | false to true

quiet crane
#

better solution than mine i think

hardy fossil
#

just less code

hardy fossil
snow bay
#

ohh wow i didnt expect someone to actually just redo the code themselves lol, tysmmm

hardy fossil
quiet crane
#

guess so

snow bay
#

so would i just replace the current code with the one you provided?