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.