0

# UI opens but doesn't close. What am I doing wrong? [SOLVED]

Edited 1 year ago

What have I done wrong in this LocalScript? It is supposed to open and close a GUI however, the UI only opens and does not close.

game:GetService("UserInputService").InputBegan:Connect(function(Input, IsTyping)
local open = false
local close = true
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.H then
if open == false then
OpenGive()
open = true
close = false
elseif open == true then
CloseGive()
open = false
close = true
end
end
end)


The OpenGive and CloseGive functions are just UDim2 Values and a statement that prints what is happening.

1

This requires none of that and should work. (make sure the script is in the said UI, and that's is a local script but in general, it should work.)

function keyPressed(input)
if input.KeyCode == Enum.KeyCode.M then
if script.Parent.Visible = true then
script.Parent.Visible = false
elseif
script.Parent.Visible =  false then
script.Parent.Visible =  true
end
end
end

game:GetService("UserInputService").InputBegan:connect(keyPressed)

0
p.s Just change the M to H I forgot about that, because I took it from a game I'm making but a lot was changed so I just forgot. vincentthecat1 199 — 1y
0
Sorry, I only just say this and thanks for your help, it worked! iiMxtt_Destinyii 62 — 1y
0
saw* iiMxtt_Destinyii 62 — 1y
0