I have this ServerScript that controls the damage the player gives to others when they shoot and their shot hits another player. The problem is when that one player takes damage, for some reason everyone else in the game also takes damage except for the player that did the shot and I don’t know why.
ServerScript:
local replicatedStorage = game:GetService("ReplicatedStorage")
local workspace = game:GetService("Workspace")
local tweenService = game:GetService("TweenService")
local players = game:GetService("Players")
local armorRE = replicatedStorage:WaitForChild("armorUpdate")
local function damagePlayer(humanoid, damage)
local armor = humanoid:GetAttribute("armor")
local armorDamage = math.min(damage, armor)
local healthDamage = damage - armorDamage
if armorDamage > 0 then
humanoid:SetAttribute("armor", armor - armorDamage)
end
if healthDamage > 0 then
humanoid:TakeDamage(damage)
end
end
replicatedStorage.ToolRemoteEvents.Rev.OnServerEvent:Connect(function(player, mouse, tool)
local character = player.Character
local reload = character:WaitForChild("BodyEffects"):WaitForChild("Reload")
local barrel = tool.Barrel
local handle = tool.Handle
local beamDisappearTime = 0.45
if tool.Ammo.Value >= 1 then
local GUI = player:WaitForChild("PlayerGui"):WaitForChild("Weapons"):WaitForChild("Revolver")
local GoingToShootBullet = GUI:WaitForChild("MainFrame"):FindFirstChild("BulletImage")
if GoingToShootBullet then
GoingToShootBullet.ImageTransparency = 0.6
GoingToShootBullet.Name = "UsedBullet"
if not reload.Value then
reload.Value = true
barrel.ShootUI.Shoot.ImageTransparency = 0.6
barrel.ShootUI.Shoot.Visible = true
handle.ShootLight.Enabled = true
local Shoot = Instance.new("Sound")
Shoot.SoundId = "rbxassetid://1583819337"
Shoot.Parent = handle
Shoot:Play()
local StartPoint = Instance.new("Part")
StartPoint.Transparency = 1
StartPoint.Parent = workspace
StartPoint.Position = barrel.Position
StartPoint.Size = Vector3.new(0.5, 0.5, 0.5)
StartPoint.Anchored = true
StartPoint.CanCollide = false
local EndPoint = Instance.new("Part")
EndPoint.Transparency = 1
EndPoint.Parent = workspace
EndPoint.Position = mouse
EndPoint.Size = Vector3.new(0.5, 0.5, 0.5)
EndPoint.Anchored = true
EndPoint.CanCollide = false
local attachment1 = Instance.new("Attachment")
local attachment2 = Instance.new("Attachment")
attachment1.Parent = StartPoint
attachment2.Parent = EndPoint
local beam = Instance.new("Beam")
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 170, 0)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 255, 127)),
})
beam.LightEmission = 1
beam.Attachment1 = attachment2
beam.Attachment0 = attachment1
beam.Width0 = 0.002
beam.Width1 = 0.09
beam.FaceCamera = true
beam.Transparency = NumberSequence.new(0)
beam.Parent = StartPoint
local rayDirection = mouse
local rayDesti = rayDirection - tool.Barrel.Position
local ignorelist = {character, tool}
local ray = Ray.new(tool.Barrel.Position, rayDesti)
local position = workspace:FindPartOnRayWithIgnoreList(ray, ignorelist)
if position then
for i, v in pairs(players:GetPlayers()) do
if v.Character and v ~= player then
local humanoid = v.Character:FindFirstChild("Humanoid")
local distance = (mouse - tool.Barrel.Position).Magnitude
if not v.Character:WaitForChild("BodyEffects"):WaitForChild("Ragdolled").Value then
if distance <= 5 then
damagePlayer(humanoid, 28)
else
damagePlayer(humanoid, 20)
end
end
end
end
end
task.wait(0.1)
reload.Value = false
barrel.ShootUI.Shoot.Visible = false
handle.ShootLight.Enabled = false
for i = 0, 1, wait() / beamDisappearTime do
beam.Transparency = NumberSequence.new(0 + (1 - 0) * i)
task.wait()
end
beam.Transparency = NumberSequence.new(1)
beam:Destroy()
attachment1:Destroy()
attachment2:Destroy()
StartPoint:Destroy()
EndPoint:Destroy()
Shoot.Ended:Wait()
Shoot:Destroy()
end
else
if character:WaitForChild("BodyEffects"):WaitForChild('Ragdolled').Value then return end
handle.NoAmmo:Play()
end
end
end)