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

How do I make this gui open with a key instead of clicking the button?

Asked by 6 years ago

I was to make the shop open by pressing the L key instead of clicking the button. What do I have to do to make that change?

Here is the script...

local frame = script.Parent local close = frame:WaitForChild("Close") local shop = frame.Parent:WaitForChild("Shop")

shop.MouseButton1Click:connect(function() shop.Visible = false frame.Visible = true end)

close.MouseButton1Click:connect(function() shop.Visible = true frame.Visible = false end)

0
your codeblock breaked GamingOverlord756 48 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Well, in your script, you opened the GUI VIA MouseButton1Down event. If you want to open it with key, you would want to use the InputBegan event of the GameService 'UserInputService'.

local frame = script.Parent 
local close = frame:WaitForChild("Close") 
local shop = frame.Parent:WaitForChild("Shop")
local uis = game:GetService'UserInputService' -- Define it
local opened = false -- Tell the game that they haven't opened yet

uis.InputBegan:Connect(function(key, gameProc) -- Connect to the function once a button press is detected
    -- Key is the key that is pressed and gameProc basically returns a boolean whether the key was pressed in chatbox or not.
    if key.KeyCode == Enum.KeyCode.L and not gameProc then -- If the key == "L" and they're not chatting
        if not opened then -- If opened is false
            opened = true
            shop.Visible = false
            frame.Visible = true
    elseif open then -- If open is true
        open = false
        shop.Visible = true
        frame.Visible = false
    end
end
end)

Ad

Answer this question