Would'nt it sufficide in the first part to increase just an integer instead? --- local n = 0 for i, _ in ipairs(t) do n = i end for k, v in pairs(t) do if type(k) ~= "number" or k<1 or k>n then --- someting end end