Attempt to print table's names is not being printed as expected

I have created a script that prints all the table’s names inside another table in a module, here is the script:

local Module = require(script.Parent.ModuleScript)
local Stu = table.pack(Module["Gi"])
for _, pront in ipairs(Stu) do
    print(pront)
end

And here is the Module script:

return {

["Gi"] = { --Table selected
	["Lol"] = 10; --Table supposed to print
	["lal"] = 4; --Table supposed to print
};
["Hello"] = 10
}

The problem is that my code is not working as expected, and instead of printing the table’s name, it’s printing this:

table: 0xda246ce7531b6e8c

This started to happen me time ago, and i didn’t know what to do, i tried to search articles or threads, and i didn’t find one that helped me, i want to repeat that i want to print the table name, not the value. Thanks for reading.

1 Like

Thats is normal. This will be calling the tables __tostring metatable function which is returning the internal name used for that table.

If you are looking to dump out the tables content I made a small bit of code you which may help.

The _ is actually the index, which is the name of the table. pront is the value, which refers to the (reference of the) table. If you want to print the table’s name, you’d have to print the index.

1 Like

Well, what i want to do is print the name tables that are inside the table called “Gi”, i don’t want to print “Gi”, i want to print “Lol”, “lal”. And not the values.


@kingdom5 I tried to require the script, but that didn’t work:

local Table = {["Test1"] = {["Hi"] = 1, "Ho"}}
local Module = require(script.Parent.tablePrint)

Module.printTable(Table)

For any reason, i don’t think it’s your module, i got this error:

Workspace.Script:15: attempt to index local 'Module' (a function value)

Thanks for reading.

In that case, you can just use a pairs loop on Module[“Gi”] then, with the index being printed.

You can’t index a function. Try, Module(Table)

Sorry, but i want to do this automatically, that’s the only way to do it in the current script that i’m working. What i mean with automatic is that will get the names without having to write an actual name to search. I don’t know if i understood, because i got confused while i was reading your post, but thanks for helping too, i hope you explain it a bit.


@incapaxx - Thanks for helping!

@kingdom5 - Your module didn’t help me, but thanks for providing me that module! Is going to be useful for the future, back to the thread, this is what i wanted to print:

1 --Quick note: 1 is from Test1

But this was the result:

 {
   [Test1] = {
          [1] = Ho
          [Hi] = 1
       }
  }

But your gave me a good module! Thanks.

By the way you can also use Repr

1 Like