Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 3 days ago

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

2 answers

Log in to vote
0
Answered by 3 days ago

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
Ad
Log in to vote
0
Answered by
SirGamezy 152
3 days ago

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.

Answer this question