Part able to detect multiple humanoid touch at one time

So i have this hitbox that appears where the player that used the move is, and i wanted everyone nearby to take damage. so i made this script and for some reason it only prints once so im guessing it only detected one humanoid when there were multiple nearby

local HitBox = game.ReplicatedStorage.Taijutsu.KickHitbox:Clone()
HitBox.Parent = workspace
HitBox.Position = HumanoidRootPart.Position
	
HitBox.Touched:Connect(function(hit)
	local ehum = hit.Parent:findFirstChild("Humanoid") or hit.Parent.Parent:findFirstChild("Humanoid")
	if ehum and ehum ~= player.Character.Humanoid then
		print("hit")
		HitBox:Destroy()
	end
end)
1 Like

well, you’re destroying it after one person touches it which disconnects the .Touched signal. You could have it last for x amount of time, and each time someone touches it while it is active add them to a table, and then after the time is over damage them all or whatever else.

1 Like

Well, i dont want to to do it multiple times for one player, that’s why i destroyed it

1 Like

How would i do this? Im not really good with tables

1 Like

you could do something like this. This isn’t the entirety of it but an example

function startHitDetection(player, hitbox, duration)
	local Hit_Humanoids = {}
	
	local connection = hitbox.Touched:Connect(function(hit)
		local ehum = hit.Parent:findFirstChild("Humanoid") or hit.Parent.Parent:findFirstChild("Humanoid")
		if ehum and ehum ~= player.Character.Humanoid and not table.find(Hit_Humanoids, ehum) then
			table.insert(Hit_Humanoids, ehum)
			print("Added Humanoid")
		end
	end)
	
	task.delay(duration, function()
		if connection then
			connection:Disconnect()
			return Hit_Humanoids
		end
	end)
end



-- to use it do something like:
local HitBox = game.ReplicatedStorage.Taijutsu.KickHitbox:Clone()
HitBox.Parent = workspace
HitBox.Position = HumanoidRootPart.Position

local humanoids = startHitDetection(Player, HitBox, 5) -- do it for 5 seconds
-- humanoids is a table full of everyone that it hit

for i,humanoid in pairs(humanoids) do
	humanoid:TakeDamage(20) -- do whatever here
end
1 Like

Is there anything else i could do other than this, thats too much for me

1 Like

I did try out that script that you did and it did add the amount of humanoids that were touching it. its just the taking damage part

for i,humanoid in pairs(humanoids) do
	humanoid:TakeDamage(20) -- do whatever here
end

thats didnt work, and again i dont work with tables so idk how to make it work

1 Like

This is the error it gives btw

 invalid argument #1 to 'pairs' (table expected, got nil)
1 Like

Then use a debounce for the players that touched it, or create a BoolValue in each player to check to see if they’ve been touched or not.

1 Like