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

How do you see how many parts are in an game?

i want to make a TextLabel that lets you see How many parts are in an game . is it even POSSIBLE?

2 answers

✓ Accepted answer

Yes, this is in fact possible. The way you could do this is to create a table containing all the parts found. For this to work, simply redefine the text label that you want to show the part count in.

local textLabel = script.Parent
local parts = {}

for a, b in pairs(game:GetDecendants()) do
	if b:IsA("Part") then
		table.insert(parts, #parts, b)
	end
end

textLabel.Text = #parts

Yes, it's possible. Here's how:

Getting Literally Everything

game:GetDescendants()

This gets everything in the game and creates a table with the items. To get the length of the table, do:

local myTable = game:GetDescendants()
local myTableLength = #myTable

To get everything in the workspace, simply change it to game.Workspace:GetDescendants()

Getting All Parts

To get all parts, simply create a loop:

local myTable = {}

for _,obj in pairs(game:GetDescendants()) do
	if obj.ClassName == "Part" then
		table.insert(myTable, obj.Name)
	end
end

local myTableLength = #myTable

Like the other example, you can simply replace game:GetDescendants() to game.Workspace:GetDescendants() to get all parts in the workspace.

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