I’m trying make it so that when multiple people get hit ‘once’, but instead it hits multiple people more than once and if I add a return end after being damaged it only hits 1 player
The code:
spawn(function()
local Parts = GetTouchingParts(hitbox)
for i,v in pairs(Parts) do
if v.Parent:FindFirstChild('Humanoid') or v.Parent.Parent:FindFirstChild('Humanoid') then
local EnemyHumanoid = v.Parent:FindFirstChild('Humanoid')
local EHumRP = v.Parent:FindFirstChild('HumanoidRootPart')
if EnemyHumanoid then
local EnemyCharacter = EnemyHumanoid.Parent
local behindd = false
if (char.HumanoidRootPart.Position - EnemyCharacter.HumanoidRootPart.CFrame * CFrame.new(0,0,-4.75).Position).magnitude < 5.5 then
behindd = true
end
if EnemyHumanoid then
local EnemyCharacter = EnemyHumanoid.Parent
if EnemyCharacter ~= char then
if EnemyCharacter:WaitForChild("IsBlocking").Value == true and behindd == true then
local Sound = game.ReplicatedStorage.Sounds:FindFirstChild("BlockHit"):Clone()
Sound.Parent = EnemyCharacter.HumanoidRootPart
Sound.Pitch = 1 * (math.random(75, 100) / 100)
Sound:Play()
else
if char:FindFirstChild("Stun") then return end
EnemyHumanoid:TakeDamage(dmg)
Damaged = true
local Slowdown2 = Instance.new("NumberValue")
Slowdown2.Name = "SpeedBoost"
Slowdown2.Value = -EnemyCharacter.Humanoid.WalkSpeed * .7
Slowdown2.Parent = EnemyCharacter.Effects
game.Debris:AddItem(Slowdown2,.55)
create("Stun", .55, EnemyCharacter)
local Sound = game.ReplicatedStorage.Sounds:FindFirstChild("Punched"..math.random(1,5)):Clone()
Sound.Parent = EnemyCharacter.HumanoidRootPart
Sound.Pitch = 1 * (math.random(75, 100) / 100)
Sound:Play()
local ANIMATION = EnemyCharacter.Humanoid:LoadAnimation(anims.DefaultAnims:FindFirstChild("Stun"..math.random(1,3)))
for i,v in pairs(game.Players:GetChildren()) do
if v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
local mag = (root.Position - v.Character.HumanoidRootPart.Position).magnitude
if mag < 5 then
game.ReplicatedStorage.screenShake:FireClient(v,2.5,14)
end
end
end
ANIMATION:Play()
ANIMATION:AdjustSpeed(2)
local PunchEffect = EHumRP.Blunt.Hit
PunchEffect:Emit(75)
end
end
end
end
end
end
end)
end