So Ive got this gun system and its pretty bugged as in, when you fire one shot it damages the player once PER PERSON in game, so if there are 3 players in-game the target takes damage 3 times, for whatever reason the server is receiving the event once per person in-game.
ServerScript in ServerScriptService
local InflictTarget = game.ReplicatedStorage.InflictTarget
InflictTarget.OnServerEvent:Connect(function(Player,Tool,Tagger,TargetHumanoid,TargetTorso,Damage,Misc)
local CanDamage = true
print("server event happened")
print(Damage)
if Tagger and TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso and CanDamage then
while TargetHumanoid:FindFirstChild("creator") do
TargetHumanoid.creator:Destroy()
end
CanDamage = false
local creator = Instance.new("ObjectValue",TargetHumanoid)
creator.Name = "creator"
creator.Value = Tagger
game.Debris:AddItem(creator,5)
print("damage dealt")
TargetHumanoid:TakeDamage(Damage)
CanDamage = true
if Misc[1] > 0 then --knockback
local shover = Tagger.Character.HumanoidRootPart or Tagger.Character.Head
local duration = 0.1
local speed = Misc[1]/duration
local velocity = (TargetTorso.Position - shover.Position).unit * speed
local shoveForce = Instance.new("BodyVelocity")
shoveForce.maxForce = Vector3.new(1e9, 1e9, 1e9)
shoveForce.velocity = velocity
shoveForce.Parent = TargetTorso
game:GetService("Debris"):AddItem(shoveForce, duration)
end
if Misc[2] > 0 and Tagger.Character.Humanoid and Tagger.Character.Humanoid.Health ~= 0 then --lifesteal
Tagger.Character.Humanoid.Health = Tagger.Character.Humanoid.Health + (Damage*Misc[2])
end
if Misc[3] then --flame
local Debuff = TargetHumanoid.Parent:FindFirstChild("IgniteScript") or Tool:FindFirstChild("GunScript_Server"):FindFirstChild("IgniteScript"):Clone()
Debuff.creator.Value = Tagger
Debuff.Disabled = false
Debuff.Parent = TargetHumanoid.Parent
end
end
end)
LocalScript in StarterPlayerScripts (Just the part that deals with damage)
if not ExplosiveData[1] then
if HitPart and HitPart.Parent and HitPart.Transparency < 0.9 then --Test if we hit something
local TargetTorso = HitPart.Parent:FindFirstChild("HumanoidRootPart") or HitPart.Parent.Parent:FindFirstChild("HumanoidRootPart")
local Tagger = game.Players:GetPlayerFromCharacter(Tool.Parent)
local TargetHumanoid = HitPart.Parent:FindFirstChild("Humanoid") or HitPart.Parent.Parent:FindFirstChild("Humanoid")
if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
MakeBloodFX(HitPart, HitPoint, Normal, BloodEffectData, FleshHoleData)
print("damage remote fired")
game.ReplicatedStorage:WaitForChild("InflictTarget"):FireServer(Tool,
Tagger,
TargetHumanoid,
TargetTorso,
(HitPart.Name == "Head" and DamageData[3]) and DamageData[1] * DamageData[2] or DamageData[1],
{Misc[1],Misc[2],Misc[3]})
Tool.GunScript_Local:FindFirstChild("MarkerEvent"):Fire(HitPart.Name == "Head" and DamageData[3])
else
MakeImpactFX(HitPart, HitPoint, Normal, HitEffectData, BulletHoleData)
end
end
