Attempt-to-concatenate-a-string-with-a-table | Need help trying to get the name of my table

local table1 = {a = 1, b = 2}
local table2 = {c = 3, d = 4}
local table3 = {e = 5, f = 6}

local AllTables = {table1, table2, table3}

for a, b in ipairs(AllTables) do
print("Table is "..b.Name)
end

How would I accomplish this? Thanks in advance.

local AllTables = {table1, table2, table3}
this line is taking a copy of the contents of table1,2,3. Thus this becomes:
AllTables = {{a=1,b=2},{c=3,d=4}...}
If you wanted to retain the variable name you could do:
local AllTables = {["table1"] = table1, ["table2"] = table2, ["table3"] = table3}
This declares a subtable “table1” with contents that are copies of what is held in the variable table1. Then you could do:

for a, b in pairs(AllTables) do
	print("Table is "..a)
end

Be sure to use pairs() and not ipairs() as now you’re dealing with Dictionaries not tables, and dictionaries do not return in order, so ipairs will not iterate.

1 Like