Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use hotkeys such as tab to open a gui?

So Im having trouble with GUI hotkeys. I know how to script the actual hotkey, but I dont want it to be a single letter such as H, I want it to be Tab but I don't know how to do that, I also need it when you hold the tab the gui is open and when you release it goes away, my starting code is here

p = game.Players.LocalPlayer mouse = p:GetMouse()

mouse.KeyDown:connect(function(key) if key == "H" then if script.Parent.Visible == true then script.Parent.Visible = false else script.Parent.Visible = true end end end)

1 comment

0

KeyDown was deprecated a long while ago, wherever you got that from, stop using it as a source because they'll probably be using other deprecated code or utilising bad practises

1 answer

You have to use UserInputService. Here's an example that fires an event

local uis = game:GetService('UserInputService')

if uis.KeyboardEnabled then --Player is using a keyboard
	uis.InputBegan:Connect(function(input) --Something was pressed or clicked
		if input.KeyCode = Enum.KeyCode.A then --If they pressed a on the keyboard
			game.ReplicatedStorage.Event:FireServer() --Fire event
		end
	end)
elseif uis.GamepadEnabled then --player is using a controller
	uis.InputBegan:Connect(function(input)
		if input.KeyCode = Enum.KeyCode.ButtonA then --If they pressed a on the controller
			game.ReplicatedStorage.Event:FireServer()
		end
	end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.