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 3 years ago
Edited 3 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.

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 answer

Log in to vote
1
Answered by 3 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.)

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 — 3y
0
Sorry, I only just say this and thanks for your help, it worked! iiMxtt_Destinyii 62 — 3y
0
saw* iiMxtt_Destinyii 62 — 3y
0
I've marked your answer as the solution. iiMxtt_Destinyii 62 — 3y
Ad

Answer this question