So, my module script has a damage function to damage the target. problem is, when i test with 2 people, the damage is twice as much as before (1 is the original damage), same if i test with 3, 3 damage instead of 1. (almost as if it was a local script firing to the server, which it isnt.)
function tower.Attack(newTower, player)
local config = newTower.Config
local target = findNearestTarget(newTower, config.Range.Value)
if target and target:FindFirstChild("Humanoid") then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
AnimateEvent:FireAllClients(newTower, "Attack")
if target.Humanoid.Jump ~= true then
for i, plrs in ipairs(game.Players:GetPlayers()) do
if target.Humanoid.Health < config.Damage.Value then
plrs.leaderstats.Money.Value += target.Humanoid.Health
target.Humanoid:TakeDamage(target.Humanoid.Health)
else
plrs.leaderstats.Money.Value += config.Damage.Value
target.Humanoid:TakeDamage(config.Damage.Value)
end
end
end
local sound = Instance.new("Sound")
sound.SoundId = newTower.HumanoidRootPart.Attack.SoundId
sound.Parent = newTower.HumanoidRootPart
sound.PlayOnRemove = true
local random = math.random(1,2)
if random == 1 then
sound.PlaybackSpeed = 1
sound:Destroy()
elseif random == 2 then
sound.PlaybackSpeed = 0.8
sound:Destroy()
end
task.wait(config.Cooldown.Value)
if newTower.Name == "Mercenary" then
target:FindFirstChild("Humanoid").Died:Connect(function()
player.leaderstats.Money.Value += 1000
end)
end
end
task.wait(0.05)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end