Hello! I am trying to give all players cash when a mob is killed and dont know how!
Heres the code:
function tower.Attack(newTower, player)
local config = newTower.Config
local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
animateTowerEvent:FireAllClients(newTower, "Attack", target)
newTower.FireSound:Play()
target.Humanoid:TakeDamage(config.Damage.Value)
if target.Humanoid.Died then
player.Money.Value += target.Humanoid.MaxHealth
end
task.wait(config.Cooldown.Value)
end
task.wait(0.1)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end
function tower.Attack(newTower, player)
local amount = 50
local config = newTower.Config
local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
animateTowerEvent:FireAllClients(newTower, "Attack", target)
newTower.FireSound:Play()
target.Humanoid:TakeDamage(config.Damage.Value)
if target.Humanoid.Died then
for _, plr in pairs(game.Players:GetPlayers()) do
plr.leaderstats.Cash.Value += amount
end
end
task.wait(config.Cooldown.Value)
end
task.wait(0.1)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end