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.
01 | game:GetService( "UserInputService" ).InputBegan:Connect( function (Input, IsTyping) |
02 | local open = false |
03 | local close = true |
04 | if IsTyping then return end |
05 | if Input.KeyCode = = Enum.KeyCode.H then |
06 | if open = = false then |
07 | OpenGive() |
08 | open = true |
09 | close = false |
10 | elseif open = = true then |
11 | CloseGive() |
12 | open = false |
13 | close = true |
14 | end |
15 | end |
16 | 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.)
01 | function keyPressed(input) |
02 | if input.KeyCode = = Enum.KeyCode.M then |
03 | if script.Parent.Visible = true then |
04 | script.Parent.Visible = false |
05 | elseif |
06 | script.Parent.Visible = false then |
07 | script.Parent.Visible = true |
08 | end |
09 | end |
10 | end |
11 |
12 | game:GetService( "UserInputService" ).InputBegan:connect(keyPressed) |