How to open UI when a button is pressed?

So I made some UI and I remembered I suck at scripting. What I want to do is open the UI when a button on the keyboard is pressed.

I know how to open the UI on a timer with a script but idk how to open it when a button is pressed.

What api[ or whatever it’s called ] could I use to achieve this?

Check this: Buttons and Text Input | Roblox Creator Documentation

1 Like

Wouldn’t that only work if you clicked it with your mouse? Or clicked it on mobile?
What I’m trying to do is open the ui when a button on the keyboard is pressed, like f or something.

Sorry if I sound dumb…

Userinputservice.
https://developer.roblox.com/en-us/api-reference/class/UserInputService

1 Like

Oh my bad, but lets say you want to use E

code

1 Like
local UIS = game:GetService("UserInputService")
local toggle = false

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if toggle then
			script.Parent.Visible = false
			toggle = false
		elseif not toggle then
			script.Parent.Visible = true
			toggle = true
		end
	end
end)

Local script place it inside whatever UI you want to “open”. This script will toggle the visibility of the particular UI element whenever the “E” key is pressed.

1 Like