How do you replace the inside of a table with another table

For example:

local something =
{
	["thing"] = 
	{
		["levels"] = 3,
		["exp"] = 500,
		["quests"] = math.huge
	}
}

local newthing = 
	{
		["somethingelse"] = 33,
		["iranoutofideas"] = 192020,
		["skins"] = "hi"
	}

something["thing"] = newthing -- this doesnt work and leads to a cyclic table reference

If you’re getting a cyclic table reference from something["thing"] = newthing it’s likely because newthing already seems to reference something directly or indirectly creating a loop

In your current example, newthing is not referencing something so something["thing"] = newthing should work perfectly and replace the inner table

Heres a code reference:

local something = {
[“thing”] = {
[“levels”] = 3,
[“exp”] = 500,
[“quests”] = math.huge
}
}

local newthing = {
[“somethingelse”] = 33,
[“iranoutofideas”] = 192020,
[“skins”] = “hi”
}

something[“thing”] = newthing – This is valid

Just realised that i named both of the tables the same thing so i was basically doing something[“thing”] = something I’m a total idiot thanks

1 Like