Why can't I print the contents of this table?

Just trying to add the name of a player to a table each time they click a button,
but for some reason it refuses to work.
The “print(“hello”)” works just fine, so I’m just really confused what’s going on.
script:

local Table = {}
script.Parent.MouseButton1Click:Connect(function()
	local plr = game:GetService("Players").LocalPlayer
	table.insert(Table, plr.Name)
	print(Table)
	print("hello")
end)

It needs to know where in the Table you want to print.
In this case you want print(Table[1]) , pulling the first value in the table.

more info: Tables

Thank you! I’ll keep this in mind for later things.

You can use

print(table.unpack(ArrayName))

to print all of the array’s values at once as well, which is more in-line with how many other programming languages work while printing arrays, rather than printing the memory address of the array. (thx Forummer)

3 Likes

It should be noted that this will only work for arrays. The following script prints an empty result.

local tables = {["A"] = 1, ["B"] = 2, ["C"] = 3}
print(table.unpack(tables))

Roblox has a built-in feature which allows you to print a table’s contents via print(tables) instead of it printing the table’s address in memory.

More info here:

2 Likes