✓ Accepted answer
This is a sort of difficult thing to do. I actually wrote a module that, among other things, handles this. Check it out here
Here's a demo:
local UserInputService = require(MODULESCRIPT)
local Keys = UserInputService.Keys
local LeftAlt = Keys.LeftAlt
local Q = Keys.Q
local Parent = script.Parent
local Connection = (LeftAlt + Q):Connect(function()
Parent.Enabled = not Parent.Enabled
end)
If you really want to do it without using a ModuleScript, there is a way. I recommend using the way above, because it is much cleaner, and I wrote it to be as efficient as the following way (as far as calling the function goes). If you write a game with a lot of different Keys that trigger things, it's easier to use the above syntax. If you want to do it the long way, here is how you might go about it:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Q = Enum.KeyCode.Q
local LeftAlt = Enum.KeyCode.LeftAlt
local Player = Players.LocalPlayer
local Parent = script.Parent
local GuiEnabled
UserInputService.InputBegan:Connect(function(Input, GuiProcessed)
if not GuiProcessed and Input.KeyCode == Q then
local KeysBeingHeldDown = UserInputService:GetKeysPressed()
for i = 1, #KeysBeingHeldDown do
if KeysBeingHeldDown[i].KeyCode == LeftAlt then
if GuiEnabled then
GuiEnabled, Parent.Enabled = false
else
GuiEnabled, Parent.Enabled = true, true
end
break
end
end
end
end)
2 comments
I'm thinking you put if input.KeyCode == Enum.KeyCode.LeftAlt and input.KeyCode == Enum.KeyCode.Q then
Tried that already and nothing happened.