How do i print whats inside a table?

ive already attempted to try to print whats in a table but when i do this:
print(#usedID) it prints 1. Cause there is 1ID Value in the Table. But i want i to print the actual ID in the table.

local usedID = {} 
if plrID.Value == '' then

for i = 65, 90 do
characters[#characters+1] = string.char(i)
end

for i = 0, 9 do
	characters[#characters+1] = tostring(i)
end	

local function randomString()

local result = ""

for i = 1, 10 do
	result = result..characters[math.random(#characters)]
    end

return result

end	
plrID.Value = (randomString())
print(player.Name.."'S ID is "..plrID.Value.." . This will be useful in the Future!")
table.insert(usedID,plrID.Value)
wait(1)
print(#usedID)
elseif plrID.Value ~= nil then
 warn(player.Name.." already has a ID!")
7 Likes

To print each value in the usedId table:

for i, val in pairs(usedId) do
    print(val)
end

Where i is the index and val is the value. If you wanted just the first value, you can use usedId[1].

I’m not sure why you are using a table for storing one value, when you could just use a variable. However, the method opens up the most possibilities.

15 Likes

print(unpack(table)) is here for your help!

Update: Since this answer has been getting thumbs ups, I want to inform everyone that the new console supports directly printing tables. (I don’t remember if it is still in beta)

14 Likes

Thank, this works! Your the solution!

3 Likes

I know it has been almost a year since you posted this question, but for future people that wants to know how to do, this works for me:

table.foreach(tableName, print)

16 Likes