Hello DevForum, I’m making a combat system by using OOP and MetaTables, but I came across an error:
The combo, which starts at 1, doesn’t increase per m1, it just stays at 1.
Here is my code:
function CombatModule.new(player : Player, weapon : StringValue)
local self = setmetatable({}, CombatModule)
self.Player = player
self.Weapon = weapon
self.ComboCooldown = 1
self.Windup = .15
self.M1Time = .3
self.LastM1 = 0
self.LastComboEnd = 0
self.M1Cooldown = false
self.Combo = 1
self.MaxCombo = 5
self.Damage = 5
self.Animations = {}
for i,v in Animations:GetChildren() do
self.Animations[v.Name] = player.Character.Humanoid.Animator:LoadAnimation(v)
end
return self
end
function CombatModule.CanDoAction(character : Model)
if character:GetAttribute("Stunned") == false and character:GetAttribute("Action") == nil then
return true
else
return false
end
end
function CombatModule:BeginCombat()
local character = self.Player.Character
local combo = self.Combo
if character then
if self.M1Cooldown == false and CombatModule.CanDoAction(character) then
self.M1Cooldown = true
if os.clock() - self.LastM1 >= 1 then
combo = 1
end
self.LastM1 = os.clock()
print(combo) -- This is where it returns 1
if combo > self.MaxCombo then
combo = 1
else
combo += 1
end
self.M1Cooldown = false
end
end
end
Feedback is appreciated!