Continuous issue of humanoids taking damage repeatedly by region3

Hey, I have been playing around, and I want to transform the multiple-target sword to a 3D region, now it is quite buggy.

This is my old post of someone helping me making a sword attacking multiple targets: Attacking multiple targets at once?

		local min = blade.Position - (0.5 * blade.Size)
		local max = blade.Position + (0.5 * blade.Size)
		local region = Region3.new(min,max)

		for _,hit in pairs(game.Workspace:FindPartsInRegion3(region,blade)) do

			if script.Active.Value == true then
				local plr = plrS:FindFirstChild(tool.Parent.Name)
				if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Enemy") then
					if hit.Name ~= "Blade" then
						if hit.Parent.Enemy.Value == true then
							local eneH = hit.Parent.Humanoid
									
							local found
							for _, character in next, hitE do
								if character == eneH then
									found = true
								end
							end
							
							if not found then
								print(eneH.Name)
								table.insert(hitE, eneH) 
								if eneH:FindFirstChild("creator") then
									if eneH.creator.Value ~= plr then
										local creator_tag = Instance.new("ObjectValue")
										creator_tag.Value = plr
										creator_tag.Name = "creator"
										creator_tag.Parent = eneH
									end
								else
									local creator_tag = Instance.new("ObjectValue")
									creator_tag.Value = plr
									creator_tag.Name = "creator"
									creator_tag.Parent = eneH
								end

									local dmg = rand:NextNumber(setting.Minimum_Damage,setting.Maximum_Damage)
									local absolutedmg = dmg
									 + math.abs(reps.Players[plr.Name].skills.strength.Value)*1.66
									module.DamageIndicator(absolutedmg,hit.Parent.Head.CFrame * CFrame.new(rand:NextNumber(-.1,.1),2,rand:NextNumber(-.1,.1)))
									eneH:TakeDamage(absolutedmg)

								end
				
								wait(.3)
								for i, character in next, hitE do
									if character == eneH then
										--script.Active.Value = false
										tool.ServerBlade.BrickColor = BrickColor.new("Bright red")
										table.remove(hitE, i)
									end
								end
							end
						end
					end
				end
			end

I removed a lot of unnecessary code, to try and make it cleaner, now the result is that it deals damage over, and over again. But I know the reason is because of the for loop of the region.
I don’t know how to solve this issue.

That is the problem (yellow numbers are the damage I deal, it deals damage over-time…)
https://gyazo.com/a92084407bba141f6da2f2affbb8a1df

1 Like

You need to filter out the humanoids that already took damage. It keeps iterating over multiple parts of the same character.

Pretty sure this part should be doing it, or am I doing it wrong?

							for i, character in next, hitE do
								if character == eneH then
									--script.Active.Value = false
									tool.ServerBlade.BrickColor = BrickColor.new("Bright red")
									table.remove(hitE, i)
								end
							end
1 Like

But the in pairs goes over all parts from beginning. The humanoid table should be out of the loop.

That was what I was beginning to do, so I loop the region3 parts inside the for loop, add humanoids into a table, and then deal damage outside the for loop and remove the humanoids from the table that they were added to?

Perhaps limiting the damage by checking if the player is swinging the sword. If they aren’t, don’t deal any damage.

using a debounce here should help. as @Operatik said. limiting the damage if the player isn’t swinging. this can be done by using a simple debounce