Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I find everything in table1 then insert to table2 that has no keys?

local DefaultTableFormat = {Tables = {Tables2 = {Tables3 = {Tables4 = {}}}},Money = 0, Girls = 0, House = 0, A = {B = {C = { D = {F = {G = {H = {I = {J = {}}}}}}}}}}
local PlayerTableFormat = {Money = 0, Girls = 0}

-- How would I insert all of them
-- For example I would have to do
	
	
	
for i,v in pairs(DefaultTableFormat) do
	if not PlayerTableFormat[i] then
		PlayerTableFormat[i] = v
	end
	-- THen I would go on to 
	
	for k,d in pairs(v) do
		if not PlayerTableFormat[i][k] then
			PlayerTableFormat[i][k] = d
		end
		-- and on and on
	end
end

-- But is there an easier and more efficient way to automate this process? I couldn't think of one

Basically I want to add keys but automate it and make it more efficient

I also had trouble with numbers since you cant do for i,v loops on numbers

1 answer

This is how you can insert tables into tables or just insert anything to a table :

local table1 = {“Hello World”}  -- this is the table that will put inside the other
local table2 = {1+1,false} -- This is the table that will soon have table one inside

table.insert(table2,2,table1) -- Goes like this (Table that you want to insert a value inside,position inside the table,the value)

for i,v in pairs(table2) do -- You don’t have to copy this it’s just to see the results
      print(i, v) -- Basically the position, the value
end

print(table1[1]) -- Prints the first position inside table1 which is the only position

It should print in order : 2,Table : (random letter/numbers),false,Hello World

This discussion is preserved as it was. New answers, comments, and votes are closed.