Two Keys Pushed Simultaneously

Hey there,

I’m working on this side project and I’m trying to figure out if there is a way that if a key is pushed/pressed, another key is also pushed. For example, if LeftShift is pushed then F is pushed as well. I’ve searched up a couple of articles but I’m still unsure on how to get started and if it’s possible.

Does anyone have any tips or guidance that can help me code this?

Video example: twopush.mp4 - Google Drive

(Left shift triggered the slide and pressing F triggered the block)

So the player inputs LeftShift for the slide, then they push F for the Block?
Or do you want the F input to automatically get triggered after the LeftShift slide?

I would just use UserInputService's InputBegan and detect when F is pushed then use UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) if F is pushed and IsKeyDown returns true, you know LeftShift and F are both down. You can also detect it in reverse and check InputBegan's event against LeftShift and IsKeyDown(Enum.KeyCode.F)

I’m still new to scripting so I’m not 100% sure where to branch off from but this is what I got so far:

local inputservice = game:GetService(“UserInputService”)
inputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
print()
end
end)

Kinda of the opposite, LeftShift would trigger the F input is what I’m looking for

That’s what I said.
“Or do you want the F input to automatically get triggered after the LeftShift slide?”

If you want the block triggered every time you hit LeftShift just play the block animation after you play the slide animation.

The block is it’s own function so it blocks attacks from players that would be attacking the said player. Wouldn’t just playing the block animation just be an animation thus the player would get hit if someone were to hit them?

So then can’t you just call that function at the end of the slide function?

That’s where I’m unsure on how to get started

So your script right now is taking the LeftShift input and just printing nothing…
Do you know how to call the Sliding function there?
If you can call the Sliding function then you can call the Blocking function in that same if statement:

if input.KeyCode == Enum.KeyCode.LeftShift then
     --call the Sliding function
     --call the Blocking function
end

When copying scripts you need to put three backtics (```) before and after the script so it will display here properly.

thx for that tip I was confused on how the script was done
So this is what I got so far but I’m not sure if I called the functions correctly:

	inputservice.InputBegan:Connect(function(input)
	    if input.KeyCode == Enum.KeyCode.LeftShift then
    local function printSlide()
	print("SlideAbility")
    local function printBlock()
	print("Blocking")
     end

You don’t put the functions inside the if statement. That only checks to see if you’ve input LeftShift.
The functions are separate sections of the entire script, but you can ‘call’ them from inside the if statement to work. This makes it easier to have a section of code that you can use in many parts of a script.
Try reading the developer.roblox.com site and using the Search tool there to look up better answers than I have: Functions | Roblox Creator Documentation

alright thx I’ll look into it :>