I want to make it so when you punch two people at a time, they both get hit. However, for some reason only one random person gets hit.
Script:
script.Parent.OnServerEvent:Connect(function(Player)
local Hitbox = Instance.new("Part", game:GetService("Workspace"))
Hitbox.Size = Vector3.new(4,2,3)
Hitbox.Material = Enum.Material.Neon
Hitbox.BrickColor = BrickColor.new("Really red")
Hitbox.Transparency = .75
Hitbox.CanCollide = false
Hitbox.Massless = true
local Weld = Instance.new("Weld", Hitbox)
Weld.Part0 = Hitbox
Weld.Part1 = Player.Character.Torso
Weld.C0 = Hitbox.CFrame:ToObjectSpace(Hitbox.CFrame * CFrame.new(0,0,2))
local Damage = 8
local OnCooldown = false
Hitbox.Touched:Connect(function(Hit)
if not Hit:IsDescendantOf(Player.Character) and Hit and Hit.Parent then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
if OnCooldown == false then
OnCooldown = true
Humanoid:TakeDamage(Damage)
local p1 = game.ReplicatedStorage.Sounds.Punched1:Clone()
local p2 = game.ReplicatedStorage.Sounds.Punched2:Clone()
local p3 = game.ReplicatedStorage.Sounds.Punched3:Clone()
local p4 = game.ReplicatedStorage.Sounds.Punched4:Clone()
local hit1 = Humanoid:LoadAnimation(script.H1)
local hit2 = Humanoid:LoadAnimation(script.H2)
local hit3 = Humanoid:LoadAnimation(script.H3)
local hit4 = Humanoid:LoadAnimation(script.H4)
local ran = math.random(1,4)
if ran == 1 then
hit1:Play()
p1.Parent = Humanoid.Parent.Torso
p1:Play()
elseif ran == 2 then
hit2:Play()
p2.Parent = Humanoid.Parent.Torso
p2:Play()
elseif ran == 3 then
hit3:Play()
p3.Parent = Humanoid.Parent.Torso
p3:Play()
elseif ran == 4 then
hit4:Play()
p4.Parent = Humanoid.Parent.Torso
p4:Play()
end
if Humanoid.Parent.Name ~= ("Ball") then
local Hplr = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
game.ReplicatedStorage.RemoteEvents.Stunned:FireClient(Hplr)
end
end
end
end
end)
wait(.2)
Hitbox:Destroy()
end)
I want them both to be getting hit, but it just hits a random one. How do I fix this?