Combo reset after x amount of time

My goal is to make Client based Combat system with Swing animations going from 1 to 4.
Pretty much you start at #1 then you go to #2 etc. If you are on #2 or higher in the combo and after say 1 second goes by after you swing then it will revert back to the First combo.

1 Like

Here is one way to do combo reset, by using a timer module to time and execute code after the timer runs out.

1 Like
local timeSinceLastHit = 0 --records time since last hit 0 is initial value
local combo = 0 --records combo 0 is initial value

	while task.wait(1) do
		if tick() - timeSinceLastHit >= 3 then --check if 3 seconds have elapsed since last hit
			combo = 0 --reset combo back to 0
			--if another hit occurs do some other code
			if combo >= 3 then
				--do extra damage for example

if hit then --hit is a made up variable which is just set to true whenever the player hits another player
	combo += 1 --increment combo by 1
	timeSinceLastHit = tick() --get time when hit occurred

Here’s a fairly primitive way of going about this, hopefully everything makes sense to you. I’ve added comments to guide the process.


used the TweenService idea found in reading this and it works very well


this isnt the “best” way but its a way :skull:

What would the best way be, if this isn’t it?

1 Like

I put this above any thing else, for a WeaponAttack function.
have the lastAttack

function Attack()
    local newAttack = tick()
    if (newAttack - lastAttack > 1.5) or (combo > 4) then
        combo = 1
    end lastAttack = newAttack

    -- put the rest of your code below hehe :D

you can change the “1.5” to whatever time you want to check for a reset.

edit: sorry for the late response

1 Like

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