I'm trying to make a part that'll damage humanoids that touch it but only if they are not in the table. Once they've been touched, they'll be put inside the table and won't be able to take any more damage for one second.
local checkList = {} local debounce2 = false hitBox.Touched:Connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') and not debounce2 then debounce2 = true for i,v in pairs(checkList) do if v == hit.Parent then -- do nothing elseif v ~= hit.Parent then table.insert(checkList,hit.Parent) v.Humanoid:TakeDamage(10) wait(1) debounce2 = false end end end end)
Table keys are very useful for this. Instead of looping through the table, you could change the way you store information such that accessing it is easier for your purposes:
local checkList = {} hitBox.Touched:Connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then if not checkList[hit.Parent] then -- If the player is not in the table: v.Humanoid:TakeDamage(10) -- Take damage checkList[hit.Parent] = true -- Store true with the key hit.Parent wait(1) checkList[hit.Parent] = nil -- And then remove it so that they can once again take damage end end end)