Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years 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.

01game: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
16end)

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

1 answer

Log in to vote
1
Answered by 4 years ago

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

01function 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
10end
11 
12game: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 — 4y
0
Sorry, I only just say this and thanks for your help, it worked! iiMxtt_Destinyii 62 — 4y
0
saw* iiMxtt_Destinyii 62 — 4y
0
I've marked your answer as the solution. iiMxtt_Destinyii 62 — 4y
Ad

Answer this question