I created a laser gun and so when the gun kills a zombie it gives the player +5 points, but it's giving them over 200 points for killing one zombie even though I'm only adding +5 points..
I'm using the Humanoid.Died function, I added a print and it printed "Died!" 30 times into output..
What is wrong with this? Is this a bug or something because after I kill the zombie it fires but it runs like 30 times?
--// Variables
local replicatedStorage = game:GetService('ReplicatedStorage')
local remotesFolder = replicatedStorage:WaitForChild('Remotes')
local laserEvent = remotesFolder:WaitForChild('FireLaser')
--// Main
--laserEvent:FireServer(mouse.Hit.p, handle.CFrame.p)
laserEvent.OnServerEvent:Connect(function(player, mousePos, handlePos)
local ray = Ray.new(handlePos, (mousePos - handlePos).unit * 500)
local part, pos = workspace:FindPartOnRay(ray, player, false, true)
local laser = Instance.new('Part')
laser.Parent = workspace
laser.Anchored = true
laser.BrickColor = BrickColor.Red()
laser.Transparency = 0.3
laser.Material = Enum.Material.Neon
laser.CanCollide = false
local dist = (mousePos - handlePos).magnitude
laser.Size = Vector3.new(0.3, 0.3, dist)
laser.CFrame = CFrame.new(handlePos, pos) * CFrame.new(0, 0, -dist/2)
laser.Touched:Connect(function(hit)
local deb = false
local hum = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if hum and hum.Parent.Name ~= player.Name then
hum:TakeDamage(5)
hum.Died:Connect(function()
print('Died!')
local killerVal = hum.Parent:FindFirstChild('Killer')
if killerVal then
killerVal.Value = player
killerVal.Value:WaitForChild('leaderstats'):WaitForChild('Points').Value = killerVal.Value:WaitForChild('leaderstats'):WaitForChild('Points').Value + 5
end
end)
end
wait(3)
deb = true
end)
game:GetService('Debris'):AddItem(laser, 0)
end)

1 comment
maybe add a debounce at line 34