How can I setup a combo system for a tool?

Hello there!

I’m trying to create a combo system for a sword although I don’t know where to start. I know that:

  1. Would have to create a Combo variable to keep track on how many times the player clicked.
  2. Add 1 to the Combo variable everytime the player clicks and reset it back to 0 once the player reaches 3 clicks or doesn’t click on time.
  3. Use something like tick() or os.clock() to compare the last time they clicked.

The closest I’ve come is this:

local AnimSession = {}
local function Setup()
	for ind, animation in pairs(Tool.Folder:GetChildren()) do
		local index = string.gsub(animation.Name, "%D", "")
		AnimSession[tonumber(index)] = Humanoid:FindFirstChildWhichIsA("Animator"):LoadAnimation(animation)
	end
end

local CurrentClick = 0
local CurrentCD = 0.3
local ComboBreak = 1
local AttackStreak = 0
--Combo
Tool.Activated:Connect(function()
	local t = os.clock()
	if t - CurrentClick >= CurrentCD then
		if t - CurrentClick > ComboBreak then
			AttackStreak = 0
		else
			AttackStreak += 1
		end

		if math.fmod(AttackStreak, 3) == 0 then
			AttackStreak = 0
		end

		AnimSession[AttackStreak+1]:Play(0.5,AttackStreak+5)

		CurrentClick = t
	end
end)

It does work, although when I try to modify it (Such as adding sounds) it seems to just randomly break for whatever reason. Additionally, I’m also trying to make the animations activate their events (Such as an event inside of one of the swing animations to allow the sword to do damage).

How can I make a good combo system or at least try to fix the broken code I currently have?

2 Likes

don’t see why it’s breaking, try adding it, and then removing the combo, to see if it’s actually the combo counter.

Pretty sure roblox doesnt give u access to operating system(os.clock in this case).

Use a wait(3) and set the combo variable back to 0 instead.