So, I am making a script. It requires the player to press a button to activate some code, which I know how to do but now I’m trying to make another similar script that the player must press three buttons at once to activate the following code.
It doesn’t work the same as if I just do one button. how do I do key combinations?
for example… elseif input.KeyCode == Enum.KeyCode.H then
goDown()
this works to activate my goDown function but
elseif input.KeyCode == Enum.KeyCode.H and input.KeyCode == Enum.KeyCode.Y then
goDown()
does not work, and I’ve played around with this. nothing seems to be working.
Need to split that up into Began and Ended.
You can test if multiple keys began…
local keysPressed = {}
local function onInputBegan(input)
keysPressed[input.KeyCode] = true
if keysPressed[Enum.KeyCode.H] and keysPressed[Enum.KeyCode.Y] and keysPressed[Enum.KeyCode.G] then
goDown()
end
end
local function onInputEnded(input)
keysPressed[input.KeyCode] = nil
end
game:GetService("UserInputService").InputBegan:Connect(onInputBegan)
game:GetService("UserInputService").InputEnded:Connect(onInputEnded)
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function()
if UserInputService:IsKeyDown(Enum.KeyCode.Q) and UserInputService:IsKeyDown(Enum.KeyCode.E) then
--Do something
end
end)