Table.Insert is resulting in a nil

For some reason, I keep getting an error saying the interval is empty when referencing a table.
The problem is the table shouldn’t be empty but it is for some strange reason that I can’t figure out.
image
Everything works except this one line


and it’s messing up this:

Does anyone know why this might be happening and how to fix it?

fixed it by this:

This happens if you pass the 2nd argument when it isn’t necessary to do so, in other words the index number at which you’re specifying the new item should be inserted at is already the index after the current final index (end of the array) which is the default position when table.insert() is called anyway.

Just stumbled here following the header. Another common way to get nil out of table.insert is to forget how table.insert works. In luau,

table.insert(table, object_to_insert) – Do this

table = table.insert(table, obj_to_insert) – Do not do this

2 Likes