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

How do I print the number of {} table?

	local instances = {}

for _,child in pairs(workspace.Servers:GetChildren()) do
    if child:IsA("Folder") then
        table.insert(instances, child)
    end
end

print(unpack(instances));

In the output, it would say, "Folder Folder" But I Want it to become "1 2" counting the specific objects instead of nouning them. I've been trying to go in the wiki but I can't really find anything... Thanks in advance!

1 comment

0

Could you accept my answer if it helped you.

1 answer

✓ Accepted answer

Use the unary length operator, #.

This is all you need. The unary length operator gets how many elements are in a table.

So don't unpack it, you can instead just get the length:

print(#instances)

However this won't print 1 2, it will just print 2. If you really want to print the former, you can insert the index instead of the child reference:

for pos, child in ipairs(workspace.Servers:GetChildren()) do
	if child:IsA("Folder") then
		table.insert(instances, pos)
	end
end

And you can unpack it

print(table.unpack(instances))

1 comment

0

Omg... Thank you so much man you deserve respect and a good reputation. Thanks once again!

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