I'm trying to make a diagonal animation play when they keys "D" and "W" are pressed at the same time, how would I make that work?
if input1.KeyCode == Enum.KeyCode.W and D then
Yes, you can with UserInputService.
Let's say you have a function called onKeyPress that is connected to UserInputService#InputBegan
, then you could do it like this.
local UIS = game:GetService("UserInputService") local function onKeyPress(input, gameProcessedEvent) if (input.KeyCode == Enum.KeyCode.W) and (UIS:IsKeyDown(Enum.KeyCode.D) then -- Your code end end UIS.InputBegan:Connect(onKeyPress)
If the InputBegan event fires, we check if input.KeyCode
is the same as Enum.KeyCode.D
(The D Button), if it is the same, we use UserInputService#IsKeyDown
if another key is pressed down right now, in this case the W Key. If the 2nd key is pressed down too, it executes the code.
(Short disclaimer: I don't know if it fully works) If you need more infos, feel free to reply in the Comments*