Seperate Table / table.insert makes table nil

Im trying to separate 1 table into 2. While doing so, my table.insert makes the table nil. I have absolutely no clue why.

Here is the main snipit:

--Output == {3,1,2,4}--basicaly numbers 1-4 random order
--x = 4
--Seperate Tables
	local output1 = {}
	local output2 = {}
	print("a")--line 94
	for i = 1, (x/2),1 do
		print("loop",output1,output[i])--line 96
	    output1 = table.insert(output1,(#output1 +1),output[i]
        print(output1,"d")--line 98
        output2 = table.insert(output2,1,output[i+1])
	end
	print("b")

Here is the output:

table.insert returns no value. Don’t assign it to a variable if you don’t want it to be nil.

table.insert(output1, output[i])
table.insert(output2, 1, output[i+1])
1 Like

table.insert isn’t something that needs to be referenced via variables. You simply just need to put

table.insert(table,value)

or

table.insert(table,position,value)

If you’d like to see more on tables, I suggest this page on the developer hub. It has plenty of info for you.

1 Like

I have used table.insert so many times before, idk why I went dumb for an hour trying to fix this. Ty!