I am trying to make a combat system with punches. I am using GetPartBoundsInBox to act as a hitbox, but i want multiple people to be able to get hit by 1 punch, not just a random person in the box.
example: https://gyazo.com/d45d784b3ef7a4d2c88ebd1360bca8b8 (sorry for lag on this)
i want both people to get hit, not just 1
here is my script:
local char = plr.Character
local hum = char:FindFirstChild("Humanoid")
local m1Damage = 3.5
local swing
local swingMath = math.random(1,3)
if swingMath == 1 then
swing = script.Swings.Swing1:Clone()
elseif swingMath == 2 then
swing = script.Swings.Swing2:Clone()
elseif swingMath == 3 then
swing = script.Swings.Swing3:Clone()
end
swing.Parent = char.HumanoidRootPart
swing:Play()
game:GetService("Debris"):AddItem(swing, swing.TimeLength)
local pibSize = Vector3.new(6,6,8)
local pibCFrame = plr.Character.HumanoidRootPart.CFrame
local partsInBox = workspace:GetPartBoundsInBox(pibCFrame, pibSize)
local part = Instance.new("Part")
part.Parent = workspace.Fx
part.Material = Enum.Material.ForceField
part.BrickColor = BrickColor.new(255,0,0)
part.Transparency = -0.5
part.CFrame = pibCFrame
part.Size = pibSize
part.Anchored = true
part.CanCollide = false
game:GetService("Debris"):AddItem(part, .5)
if partsInBox ~= {} then
for _,v in pairs(partsInBox) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= plr.Character then
local victimHum = v.Parent:FindFirstChild("Humanoid")
victimHum:TakeDamage(m1Damage)
local maxforce2,speed2,KBParent2,KBlifetime2 = 25000,10,v.Parent.HumanoidRootPart,.1
local kb = Instance.new("BodyVelocity")
kb.Parent = KBParent2
kb.MaxForce = Vector3.new(maxforce2, maxforce2, maxforce2)
kb.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * speed2
game:GetService("Debris"):AddItem(kb, KBlifetime2)
v.Parent.unstunned.Value = false
char.Meter.Value = char.Meter.Value + 2
for i,fx in pairs(game.ReplicatedStorage.HitEffects.Punch:GetChildren()) do
if fx:IsA("ParticleEmitter") then
local new = fx:Clone()
new.Parent = v.Parent.HumanoidRootPart.RootAttachment
new:Emit(3)
end
end
local maxforce,speed,KBParent,KBlifetime = 25000,10,plr.Character.HumanoidRootPart,.1
local kb = Instance.new("BodyVelocity")
kb.Parent = KBParent
kb.MaxForce = Vector3.new(maxforce, maxforce, maxforce)
kb.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * speed
game:GetService("Debris"):AddItem(kb, KBlifetime)
local hitMath = math.random(1,4)
if hitMath == 1 then
victimHum:LoadAnimation(script.hitAnims.Hit1):Play()
elseif hitMath == 2 then
victimHum:LoadAnimation(script.hitAnims.Hit2):Play()
elseif hitMath == 3 then
victimHum:LoadAnimation(script.hitAnims.Hit3):Play()
elseif hitMath == 4 then
victimHum:LoadAnimation(script.hitAnims.Hit4):Play()
end
local soundMath = math.random(1,2)
if soundMath == 1 then
local hitsound = Instance.new("Sound", v.Parent.HumanoidRootPart)
hitsound.SoundId = "rbxassetid://9066673412"
hitsound:Play()
wait(.584)
hitsound:Destroy()
elseif soundMath == 2 then
local hitsound = Instance.new("Sound", v.Parent.HumanoidRootPart)
hitsound.SoundId = "rbxassetid://5501600429"
hitsound:Play()
wait(.584)
hitsound:Destroy()
end
wait(.5)
v.Parent.unstunned.Value = true
return
end
end
end
please help its 4 am and i cant figure this out