if you REALLY want a sparse table, then instead of insert(), do this:
t[3] = “whatever”
t[23] = “whatever”
t[93] = “whatever”
for k,v in pairs(t) do print(k,v) end
conversely, if you DON’T want a sparse table, then index it sequentially and iterate with for i=1,#t or ipairs()
right now you have half of one and half of the other, and that won’t work the way you seem to expect. it’s not a bug in tables, it’s documented behavior - you just need to figure out if you want to treat your table as an “array” (with sequential numeric keys) or as a “hash” (with arbitrary keys), then populate and iterate appropriately. if you mix the two, then the #count of the table becomes nonsense, so things like insert() won’t behave as you seem to expect.