Table is not working properly?

Hey everyone! I have a little bit of an issue here.
So to get straight, I have this script where it gets anything within the Region3 and make sure it’s a humanoid, put it in a table for a debounce, then damages it.
The problem occurs where we get the humanoids. The script attempts to get the same humanoid and object multiple time despite the debounce the script has.

 local regionpart = game.ServerStorage.Range:Clone()
			regionpart.Parent = workspace
			regionpart.Position = h.Position
			local region = Region3.new(regionpart.Position - (0.5 * regionpart.Size),regionpart.Position + (0.5 * regionpart.Size))
			local pir = workspace:FindPartsInRegion3(region,nil,math.huge)
			local humands = {}
			local function checktablevar(tab,val)
				for _,vv in pairs(tab) do
					if vv == val then
						print(val.Parent.Name)
						print("yes")
						return true
					end
				end
				print(val.Parent.Name)
				print("no")
				return false
			end
			for _,hums in pairs(pir) do
				if hums.Parent:FindFirstChildWhichIsA("Humanoid") then
					if not checktablevar(humands,hums) then 
						table.insert(humands,hums.Parent:FindFirstChildWhichIsA("Humanoid"))
					end
				end
			end

It damages the dummies till death and never prints yes. What do I do?
image

1 Like

vv is never equal to val because you insert the Humanoid into the table instead of the Part (hums / val) you’re checking against.

You can fix this by either inserting the Part into the humands array:

table.insert(humands, hums);

Or by checking against the actual Humanoid:

if not checktablevar(humands, hums.Parent:FindFirstChildWhichIsA("Humanoid")) then 
1 Like

In line
if vv == val then
vv won’t equal to val because vv is Humanoid and val is part. So it will keep printing no.
Change that line :
if not checktablevar(humands,hums) then
to:
if not checktablevar(humands,hums.Parent.Humanoid) then

1 Like