UserInputService Help

Hi,

I’m quite new to UserInputService and I’m trying to make it so that we need to press 2 keys to fire something.

For example
Shift + F to fire something.

I’ve tried to look for other posts on the DevForum and tutorials but I didn’t know how to describe this thing. Any help is appreciated!

3 Likes

Here’s one way you can do it:

UIS = game:GetService("UserInputService")

local Key1 = false
local Key2 = false

UIS.InputBegan:Connect(function(input, gp)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Key1 = true
	end
	
	if input.KeyCode == Enum.KeyCode.F then
		Key2 = true
	end
	
	if Key1 and Key2 then
		Key1, Key2 = false, false
		print("done") -- or whatever you want to do
	end
end)

UIS.InputEnded:Connect(function(input, gp) 
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Key1 = false
	end
	
	if input.KeyCode == Enum.KeyCode.F then
		Key2 = false
	end
end)
2 Likes

Thanks, This helped me a lot! :smiley:

1 Like