How to damage multiple people using getpartboundsinbox()?

I have an odd feeling that this is very very simple,

here is the current code i have

PunchEvent.OnServerEvent:Connect(function(Player, HitContents, Params)
	for i,v in ipairs(HitContents) do
		local e_character = v.Parent
		local e_humanoid = e_character:WaitForChild("Humanoid")
		
		if e_humanoid then
			if not hitlist[e_humanoid] then
				
				hitlist[e_humanoid] = true
				e_humanoid:TakeDamage(10)
				hitlist[e_humanoid] = false
				break
			end
		end
		
	end
end)

the code has been reworked time and time again so not much is there.
I put it in a server because doing the hitbox locally causes there to be delays based on ping which I’m attempting to avoid.
If anyone could explain how I would go about damaging multiple humanoids that would be great, because currently when I click it only damages a single humanoid. I’ve researched for houuurrrssssssssssss

1 Like

Did you receive an ā€œInfinite yield possibleā€ error in the output (or something like that)?

1 Like

any reason why it need to ā€œbreakā€ here? maybe it should be continue? since it look like it deal damage once and then break the loop

1 Like
PunchEvent.OnServerEvent:Connect(function(Player, HitContents, Params)
	local hitList = {}

	for i,v in ipairs(HitContents) do
		local character = v.Parent
		local humanoid = character:FindFirstChildOfClass("Humanoid")

		if humanoid then
			if not table.find(hitList, humanoid) then
				table.insert(hitList, humanoid)
				humanoid:TakeDamage(10)
			end
		end
	end
end)
1 Like

I use break because if I don’t put it, it constantly damages the area

A little tangental but u should probably only send the humanoid to the server as itll reduce the overhead

You can just do the same thing with the hitplayers table locally

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.