How can I make a combo system?

Hello, So I’m making a game and I want it so that if you press like left click, right click, left click it does something. I don’t know how to make it like that so help would be appreciated.

1 Like

Look into UserInputService. Your script it should make an event once input begins, add a conditional to identify the input, and your script can go on from there

I know but how can I make it so that you need to press the mouse buttons in a certain order to trigger something? I only know how to make it so that if you press one button it does something

You can make variables for each button that the player clicks and add a wait so the player has enough time to click the second button. After setting the variable, check if those inputs match your desired key

That’s too complicated for me to understand. Can you put it in a script so I can understand it better?

Example code

local UIS = game:GetService("UserInputService")
local db = false
local waitTime = 1

UIS.InputBegan:Connect(function(key)

if key.KeyCode == Enum.KeyCode.LeftShift and db == false then

UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.A and db == false then
db = true
print("Combo pressed")
wait(waitTime)
db = false
end
end)
end
end)

Try using this script to see if it works!

Sorry for the bad formatting I’m on mobile.

I’ll try it out and see if it works

1 Like

Alright I tried it out and when I press shift I can spam a and it says combo pressed. Also when I press a once it sends a couple of combo pressed.

Use variables which activate on MouseButton1Down and Up and for 2 which is the right button then check that;

Try the new script I just made a small change

Nope. Still doesn’t work as intended

Try now, hopefully it should work

Still I can press shift and then spam a but it has a little bit of a cooldown

Thats what I tried doing. This is only a test so don’t worry about all the messy code.

local UIS = game:GetService("UserInputService")
local db = false
local waitTime = 1
local apress = false
local dpress = false

local test = coroutine.create(function()
while wait(0.1) do
	print(apress)
	print(dpress)
end
end)

local joe = coroutine.create(function()
print("aa")
wait(1)
apress = false
dpress = false
end)

coroutine.resume(test)

UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.A then
	apress = true
	coroutine.resume(joe)
end

if key.KeyCode == Enum.KeyCode.D then
	dpress = true
	coroutine.resume(joe)
end

if key.KeyCode == Enum.KeyCode.T and dpress and apress then
	print("joe")
	apress = false
	dpress = false
end
end)
local pressedFirstKey = false

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end
	if input.KeyCode == Enum.KeyCode.LeftControl then -- If we push down left control then
		pressedFirstKey = true -- Set the variable to true
		print("Started combo")
	end
end)

userInputService.InputBegan:Connect(function(input, gameProcessedEvent) 
	if gameProcessedEvent then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then -- If we click the left mouse button then
		if pressedFirstKey == true then -- checks if the combo has been started
			print("Ended combo") 
			pressedFirstKey = false -- Sets the variable to false
		end
	end
end)

Just wrote this up go try it out in studio tell me if it works.

You forgot to set the userInputService variable, I did that and it works but I want it so that if you like press control and wait like one second the combo ends and nothing gets executed and you have to press the control key again to start the combo.

Sorry that it took so long since i was overcomplicating it. Anyway this should work as intended now.

local pressedFirstKey = false
local timeWaited = 0
local userInputService = game:GetService("UserInputService")
local start = false

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		pressedFirstKey = true
		start = true
		print("Started combo")
		wait(5)
		if start == true then
			timeWaited += 5
		end
	end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if pressedFirstKey == true then
			if timeWaited < 5 then
				print("Ended combo") 
				pressedFirstKey = false
				timeWaited = 0
				start = false
			end
		end
	end
	if timeWaited >= 5 then
		if pressedFirstKey == true then
			if start == true then
				start = false 
				pressedFirstKey = false
				timeWaited = 0
			end
		end
	end
end)
2 Likes

Ty it worked. Now with a little bit of tweaking and some coding I can do what I want