How do i make a frame become visible by clicking button on Keyboard(B)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Making Frame visible by clicking button on keyboard
  2. What is the issue? Include screenshots / videos if possible!
    Idk how to do that
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Was looking on youtube and dev hub, but didn’t find anything

My script:

local Button = Enum. -- So i stuck at start xD

Use UserInputService and Enum.KeyCode.

local UIS = game:GetService("UserInputService")
local button = Enum.KeyCode.F --F is just a random one
local frame = --the frame path

UIS.InputBegan:Connect(function(input, typing) --input returns the key pressed and typing says if it is processed.
    if not typing and input.KeyCode == button then
        frame.Visible = true
    end
end)
2 Likes

That works, but how do i close by the same button?

local UIS = game:GetService("UserInputService")
local button = Enum.KeyCode.F --F is just a random one
local frame = --the frame path

UIS.InputBegan:Connect(function(input, typing) --input returns the key pressed and typing says if it is processed.
    if not typing and input.KeyCode == button then
        frame.Visible = not frame.Visible
    end
end)

Mark @Kaid3n22 's post as a solution.

1 Like