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.
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)