im making a combat script, and it works as intended but i’d like it to damage multiple humanoids and not just one humanoid. I have an explosion move and it only damages one humanoid but id like it to damage more. I looked around on dev forum and i found out you have to put each humanoid in a table, and loop through it but im not sure how.
sword.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Block") then return end
if not hit.Parent:IsA("Model") and hit.Parent:WaitForChild("Humanoid") then return end
if not hit:IsA("BasePart") then
return
end
if hit.Parent.Name == plr.Name then return end
if hit:IsA("BasePart") then
local hum = hit.Parent:WaitForChild("Humanoid")
local humPart = hit.Parent:FindFirstChild("HumanoidRootPart")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8260898836"
local track = hum:LoadAnimation(animation)
local lookDirect = humPart.CFrame.LookVector
---------------------------
local Speed = 45
local Force = 8000000
local TotalForce = Force
local KnockBack = Instance.new("BodyVelocity")
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed
if hum and hit:FindFirstAncestorWhichIsA("Model") then
hitbox.Position = humPart.Position
hitbox.Size = humPart.Size + Vector3.new(1.5,1.5,1.5)
hitbox.Parent = hit.Parent
hitbox.Anchored = false
hitbox.Transparency = 1
weld.Parent = hitbox
weld.Part0 = humPart
weld.Part1 = hitbox
hitbox.Touched:Connect(function(per)
if per.Parent == hit.Parent then return end
if db == false then
db = true
hum:TakeDamage(12)
hum.WalkSpeed = 0
hum.JumpHeight = 0
track:Play()
KnockBack.Parent = humPart
------------------------
task.wait(1.5)
hitbox:Destroy()
KnockBack:Destroy()
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
wait(10)
db = false
end
end)
end
end
end)
The most inportant part of the script is here
hitbox.Touched:Connect(function(per)
if per.Parent == hit.Parent then return end
if db == false then
db = true
hum:TakeDamage(12)
hum.WalkSpeed = 0
hum.JumpHeight = 0
track:Play()
KnockBack.Parent = humPart
------------------------
task.wait(1.5)
hitbox:Destroy()
KnockBack:Destroy()
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
wait(10)
db = false
end
end)
sword.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Block") then return end
if not hit.Parent:IsA("Model") and hit.Parent:WaitForChild("Humanoid") then return end
if not hit:IsA("BasePart") then
return
end
if hit.Parent.Name == plr.Name then return end
if hit:IsA("BasePart") then
local hum = hit.Parent:WaitForChild("Humanoid")
local humPart = hit.Parent:FindFirstChild("HumanoidRootPart")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8260898836"
local track = hum:LoadAnimation(animation)
local lookDirect = humPart.CFrame.LookVector
---------------------------
local Speed = 45
local Force = 8000000
local TotalForce = Force
local KnockBack = Instance.new("BodyVelocity")
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed
if hum and hit:FindFirstAncestorWhichIsA("Model") then
hitbox.Position = humPart.Position
hitbox.Size = humPart.Size + Vector3.new(1.5,1.5,1.5)
hitbox.Parent = hit.Parent
hitbox.Anchored = false
hitbox.Transparency = 1
weld.Parent = hitbox
weld.Part0 = humPart
weld.Part1 = hitbox
hitbox.Touched:Connect(function(per)
if per.Parent == hit.Parent then return end
local humanoids = {}
local isfound = false
for _,v in ipairs(humanoid) do
if v == hum then
isfound = true
end
end
if isfound == false then
table.insert(humanoids,hum)
hum:TakeDamage(12)
hum.WalkSpeed = 0
hum.JumpHeight = 0
track:Play()
KnockBack.Parent = humPart
------------------------
task.wait(1.5)
hitbox:Destroy()
KnockBack:Destroy()
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
wait(10)
end
end)
end
end
end)
local humanoids = {}
sword.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Block") then return end
if not hit.Parent:IsA("Model") and hit.Parent:WaitForChild("Humanoid") then return end
if not hit:IsA("BasePart") then
return
end
if hit.Parent.Name == plr.Name then return end
if hit:IsA("BasePart") then
local hum = hit.Parent:WaitForChild("Humanoid")
local humPart = hit.Parent:FindFirstChild("HumanoidRootPart")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8260898836"
local track = hum:LoadAnimation(animation)
local lookDirect = humPart.CFrame.LookVector
---------------------------
local Speed = 45
local Force = 8000000
local TotalForce = Force
local KnockBack = Instance.new("BodyVelocity")
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
KnockBack.Velocity = char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed
if hum and hit:FindFirstAncestorWhichIsA("Model") then
hitbox.Position = humPart.Position
hitbox.Size = humPart.Size + Vector3.new(1.5,1.5,1.5)
hitbox.Parent = hit.Parent
hitbox.Anchored = false
hitbox.Transparency = 1
weld.Parent = hitbox
weld.Part0 = humPart
weld.Part1 = hitbox
hitbox.Touched:Connect(function(per)
if per.Parent == hit.Parent then return end
local isfound = false
for _,v in ipairs(humanoid) do
if v == hum then
isfound = true
end
end
if isfound == false then
table.insert(humanoids,hum)
hum:TakeDamage(12)
hum.WalkSpeed = 0
hum.JumpHeight = 0
track:Play()
KnockBack.Parent = humPart
------------------------
task.wait(1.5)
hitbox:Destroy()
KnockBack:Destroy()
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
wait(10)
for k in pairs (humanoids) do
humanoids [k] = nil
end
end
end)
end
end
end)
local HitCharacters = {}
script.Parent.Touched:Connect(function(Part)
if not Part.Parent then
return
end
local Character = Part.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if not Humanoid or table.find(HitCharacters, Character) then --detect if the character recently touched the block
return
end
Humanoid:TakeDamage(50)
table.insert(HitCharacters, Character) --add the character to a debounce
task.wait(5)
local Position = table.find(HitCharacters, Character)
if Position then
table.remove(HitCharacters, Position) --remove the character from the debounce
end
end)