Combine Tables Together

This is my first Community Resources post and my “first” module that I made.

This isn’t meant to get immediate attention. This is just for people in the future who are searching for an easy way to combine multiple tables. Yes, I know there is table.move(), but I don’t understand it, sooooo ummm… Use this module I guess:

https://create.roblox.com/marketplace/asset/11676701383/Combine-Tables

To use the 1 function (lol) just do: CombineTablesModule.Combine(table1, table2, table3, etc)
Note: The function returns the elements of the tables in the order that you give it.

1 Like

You don’t need to make this a module, you can reduce the code by returning a function instead:

return function(...: {any})
    local newTable = {}
	for _, v in ipairs({...}) do -- Note: Combining tables combines the tables in order
		for i, x in ipairs(v) do
			table.insert(newTable, x)
		end
	end
	
	return newTable
end

You should also mention this combines arrays only, as tables in Lua can refer to both arrays and dictionaries.

3 Likes