How can I make a kill counter for a unit that stores the value for each kill upon upgrade(because a new version of the unit is spawned when upgraded). so I cant store the kill values inside the unit because it gets replaced by a new one
here is the attack function
function UnitSpawnModule.Attack(newUnit, player)
local Config = newUnit:WaitForChild("Config")
local target = UnitSpawnModule.FindTarget(newUnit, Config.Range.Value, Config.TargetMode.Value)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
if newUnit.Config.AttackType.Value == "Slasher" then
local targetcframe = CFrame.lookAt(newUnit.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newUnit.HumanoidRootPart.BodyGyro.CFrame = targetcframe
print(newUnit.Name.." Is a Slasher")
if newUnit.Animations.Fire:FindFirstChild("Amount") then
AnimateMultiTower:FireAllClients(newUnit, "Fire", target)
end
target.Humanoid:TakeDamage(Config.Damage.Value)
newUnit.Head.Sword:Play()
local killsValue = 0
if target.Humanoid.Health <= 0 then
killsValue += 1
player.Money.Value += target.Money.Value
player.Kills.Value +=1
newUnit.Config.Kills.Value = killsValue
print(killsValue)
end
task.wait(Config.Cooldown.Value)
end
end
task.wait(.1)
if newUnit and newUnit.Parent then
UnitSpawnModule.Attack(newUnit, player)
end
end
and here is the kill counter that I tried to make:
local killsValue = 0
if target.Humanoid.Health <= 0 then
killsValue += 1
player.Money.Value += target.Money.Value
player.Kills.Value +=1
newUnit.Config.Kills.Value = killsValue
print(killsValue)
end
task.wait(Config.Cooldown.Value)
but the problem with this is that the kill counter resets back to zero when the function is called… How can I make it so that the kill counter is stored and is unique to that specific type of unit ? thank youu