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

Making key combination using UserInputService?

Asked by 6 years ago
Edited 6 years ago

Get it? It's like when you hold down a button and press another button, it triggers something.

And also, how to make the script knows that the player has stopped pressing those keys?

1 answer

Log in to vote
0
Answered by
arshad145 392 Moderation Voter
6 years ago

Hello,

local ui = game:GetService("UserInputService") -- Get the UserInputService.

ui.InputBegan:Connect(function(input,gpe)
    if not gpe then -- If not on a gui.
        if ui:IsKeyDown(Enum.KeyCode.Space) and ui:IsKeyDown(Enum.KeyCode.W) then -- If Space AND W are being held down/ pressed at the same time, it will trigger the event you want.(In this case print)
            print("~Stuff here~")
        end
    end
end)

Reference here for the IsKeyDown() function.

You can also check KeyCodes here

If you have any question feel free to ask.

Thank you for reading.

0
This was really helpful ! Revisedy 23 — 6y
0
@arshad145 And how to know if the player has stopped pressing those buttons? Konethorix 197 — 6y
Ad

Answer this question