Help with combo function

I need help with writing a function to handle a few different things, for now I basically need it to detect if a player is holding a weapon or not - then determine if the player is on a cooldown and advance this by +1. I’ve managed to find and adapt a script that works for simply one weapon, but now I want to adapt it to handle a second weapon while using the same combo count + cooldown without completely overriding the other one but I cannot seem to figure it out. Thanks

WeaponData = {FistAttackData = {AttackCoolDown = 0, AttackTimeout = 0, ComboCoolDown = 0, StreakCount = 0, Damage = 0, MaxCombo = 0}}

GlobalAttackDebounce = {WeaponDebounce = {WeaponDebounceActive = false, LastAttemptTick = 0, LastUsedWeapon = nil}}

function Attack(Player)
	GlobalAttackDebounce.Debounce = true

	local CurrentTime = tick()
	local TimePassed = (GlobalAttackDebounce.LastAttemptTick and CurrentTime - GlobalAttackDebounce.LastAttemptTick) or 0

	local CoolDown = (GlobalAttackDebounce.StreakCount >= GlobalAttackDebounce.MaxCombo and GlobalAttackDebounce.ComboCoolDown) or GlobalAttackDebounce.AttackCoolDown

	if TimePassed <= CoolDown then
	else
		if GlobalAttackDebounce.StreakCount >= GlobalAttackDebounce.MaxCombo then
			GlobalAttackDebounce.StreakCount = 0
		end

		if TimePassed >= GlobalAttackDebounce.AttackTimeout then
			GlobalAttackDebounce.StreakCount = 0
		end

		if GlobalAttackDebounce.StreakCount <= GlobalAttackDebounce.MaxCombo then
			GlobalAttackDebounce.LastAttemptTick = CurrentTime
			GlobalAttackDebounce.StreakCount = GlobalAttackDebounce.StreakCount + 1
			
			-- 
			
		end
	end
	GlobalAttackDebounce.Debounce = false
end

( I AM AWARE THE ABOVE CODE HAS SYNTAX ERRORS )

You can see the math and this works quite well for a single weapon, but if I were to change to a second weapon for example - it would ignore the cooldown and such.

Any ideas on how to do this differently / what I should change?

tldr; need this to work with two weapons, or rather a " weapon " tool and a " fist " weapon which will NOT have a tool. :slight_smile:

1 Like

The solution… Hard values like boolValue, stringValue and such. Im guessing the cd gets bypassed because unequip → equip reloads the script or something

2 Likes

Nah it’s not that, this script is slightly different to the one I use to avoid having to post my annoying to read table - but the principal is the same. The main reason it overrides is cause the logic and math is wrong and I can’t figure out what to change it to.

the actual script has a storage area for it all so each value is stored appropriately and correctly.

2 Likes

Im sorry but can you please elaborate everything again. Didn’t understand what the issue is

2 Likes

[Post was replied to someone else instead]

You should use attributes to make it. Trust me it’s very safe & easy to work with.

1 Like

Local attributes are not safe imo

That’s why you do it on server