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

How would I insert the i and v ?

local Tab = {Tab = 'G',S = 'CCC'}


local Table = {}

for i,v in pairs(Tab) do

	
	
end


for i,v in pairs(Table) do
	print(i,v)
end




I want Table to be exactly like Table but I dont know how to do it

like I want Table to be = to {Tab = 'G', S = 'CCC'}

but table.insert cant do this so im confused

1 answer

✓ Accepted answer

You would just do this:

for k,v in pairs(Tab) do
	Table[k] = v
end

I changed the first loop variable from i to k because it's more conventional to use k for "key" for a dictionary, so that it's clear to someone reading your code that it's a dictionary not an array. Using i is the convention for "index", when looping over an array with ipairs, or as an integer counter a for loop.

This looping over a dictionary to copy keys and values is what's known as a "shallow copy", because if any values in Tab are themselves tables you will not be duplicating their contents, only creating references to them in Table. You can wrap this loop in a function though, and call it recursively to do a "deep copy" should you find yourself with this problem.

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