I’m trying to make an hitbox system that can hit multiple players and each only once. This exact script actually works on my other hitboxes so it might be a problem with something else. However, I’ve tested it and am confused. When someone is hit the output prints “False” multiple times. This means it cannot find the value of the humanoid in the “AlreadyHit” table and keeps damaging repeatedly. I also printed the table’s values after the table.insert line and the humanoid was found. I don’t know how the Humanoid is in the table but isn’t found by the searching script.
local AlreadyHit = {}
local function foundInList(Humanoid)
for _,target in ipairs(AlreadyHit) do
if target == Humanoid then
print("True")
return true
end
end
print("False")
return false
end
NewHitBox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
if hit.Parent ~= Character then
local Humanoid = hit.Parent.Humanoid
if Humanoid then
if not foundInList(Humanoid) then
table.insert(AlreadyHit, Humanoid)
hit.Parent.Humanoid:TakeDamage(10)
wait(1)
for i = 1, #AlreadyHit do
if AlreadyHit[i] == Humanoid then
table.remove(AlreadyHit, i)
end
end
end
end
end
end
end)