Damaging multiple humanoids

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.

Help is appreciated, thank you for your time :grinning:

can u show the current script??

1 Like

	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)

if u remove db completely doesnt it fix the problem?

from here. just remove db i think it allows u to hit one humanoid

i tried that but that makes the dummys die instantly since theres no cooldown on the touched event

i dont know much about these arrays but i tried:

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)
2 Likes

Under this line would i change IsFound to false? EDIT: Nevermind! just realised its not suppose to be false

@appe125 it worked but theres no cooldown when it comes to damage.

one last try:

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)

Here’s an example of something you should do:

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)

2 Likes