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

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

Asked by 4 years ago

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)

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 turtle2004 167 — 4y

1 answer

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago

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
Ad

Answer this question