Does anyone know how I can check for multiple inputs at the same time?

I’m trying to make it so that the player can use left shift and the space button to preform a move in my game, but the issue is that this does not work at all.

I’m not sure how I’m supposed to solve the issue and make it so that when I hit both keys at the same time, I can preform the move.

2 Likes

Maybe sequence the inputs, so once one is triggered, a small timer starts and if the other key is pressed in that time, it does what you want it to do

1 Like

Probably not the most effective way of doing this, but you can try this:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gpe)
	if gpe then
		return
	end
	
	if uis:IsKeyDown(Enum.KeyCode.LeftShift) and uis:IsKeyDown(Enum.KeyCode.Space) then
		--// code here
	end
end)
2 Likes

@AmoraFolf is right, you don’t use and, but you use commas, it’s the better way, but his scritp only needs an adjustment:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gpe)
	if gpe then
		return
	end
	
	if uis:IsKeyDown(Enum.KeyCode.LeftShift, Enum.KeyCode.Space) then
		--// code here
	end
end)

If I’m not wrong it should work

1 Like

You are correct as well. It is more efficient to put both in one.

Kinda rushing to get many things done at once lol

1 Like
local Combos = {
	{
		["InOrder"] = true,
		["Repeating"] = false,
		["MaxTimeBetweenKeys"] = 1, -- Disable with 0 or nil
		["Keys"] = {Enum.KeyCode.LeftShift, Enum.KeyCode.Space},
		["Function"] = function()
			print("COMBO")
		end,
	}
}


local KeysDown = {}
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed or input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	KeysDown[input.KeyCode] = os.clock()
end)
game:GetService("UserInputService").InputEnded:Connect(function(input, gameProcessed)
	if gameProcessed or input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	KeysDown[input.KeyCode] = nil
end)



while wait() do
	for _, ComboData in pairs(Combos) do
		local lastClock = nil
		local failed = false
		for i, KeyCode in pairs(ComboData.Keys) do
			local clock = KeysDown[KeyCode];
			if clock ~= nil and (not ComboData.InOrder or lastClock == nil or lastClock < clock) then
				if ComboData.MaxTimeBetweenKeys ~= nil and ComboData.MaxTimeBetweenKeys > 0 then
					if lastClock and (clock - lastClock) > ComboData.MaxTimeBetweenKeys then
						failed = true
						break
					end
				end
				lastClock = clock
			else
				failed = true
				break
			end
		end
		if not failed then
			if not ComboData.Repeating then
				KeysDown[ComboData.Keys[1]] = nil
			end
			ComboData.Function()
		end
	end
end

nope, it didn’t seem to work again

print("start of script")
local UIS = game:GetService("UserInputService")
local moveModule = require(game:GetService("ReplicatedStorage"):WaitForChild("Player"):WaitForChild("Moveset"))

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local state = moveModule.state

local moves = moveModule.moves

print("started")

UIS.InputBegan:Connect(function(input, gpe)
	if not gpe then
		if UIS:IsKeyDown(Enum.KeyCode.LeftShift, Enum.KeyCode.Space) then
			moves("LJ")
		elseif UIS:IsKeyDown(Enum.KeyCode.LeftControl) then	
			moves("Crouch")
		elseif UIS:IsKeyDown(Enum.KeyCode.E) then
			moves("Dive")
		elseif UIS:IsKeyDown(Enum.KeyCode.LeftControl) and state == "Freefalling" then
			moves("GP")
		end
	end
end)

After your InputBegan function line print input to see what you are getting, then use that information to troubleshoot.

bro what even is this

1 Like

Commas don’t do anything, you instead have to check for both inputs.

By theory though, It seems like it would work though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.