The worst part is, he didn’t even read the code nor the topic and straight-up suggested this actually useless code…
Well as @Sirian142 said, I could just use the physics tab. I gave my feedback on it. If you don’t like it cry about it.
I did, and just gave a shorter/alternative method.
“If you don’t like it cry about it.” this certainly isn’t a good display of forum etiquette at all.
I don’t mind criticism, anyone is free to give suggestions to improve my code. But there is no need to be toxic. And also, I mentioned this before but your code is very different from mine and is missing a couple of features my version has.
Here’s a shorter version of this script:
local parts = {}
parts.Total = 0
for _, part in ipairs(workspace:GetDescendants()) do
if part:IsA("BasePart") then
local count = parts[part.ClassName] or 0
parts[part.ClassName] = count + 1
parts.Total += 1
end
end
warn("Part Count:")
for class, count in pairs(parts) do
print(class .. ": " .. count)
end
Just do
local num = 0
for i, v in pairs (game.Workspace:GetDescendants()) do
if v:IsA("BasePart") then
num = num +1 print (v.Name, num)
end
end
Just from the looks I can tell it won’t work, num isn’t defined and num1 isn’t being used most likely because you made a mistake with your variables in your head, BasePart doesn’t include folders.
Also I normally make these scripts in studio in less than a few minutes to help myself and this is what I would probably do:
x=0 for _, v in pairs(workspace:GetDescendants()) do x=v:IsA("BasePart") and x+1 or x end
print(x)
I haven’t touched studio in around 5 months so I’m not sure if it works or not.
Yeah, i forgot to remove the 1. My script works fine in console so it should work in studio. It counted unions too and body parts. Hopefully it works correctly for everyone. Thank you for your correction though!
107k
I’m beyond impressed lmao
I probably didn’t get this but this just seems like a more complicated version of
local number = 0
for _, parts in pairs (game:GetDescendants()) do
if parts:IsA("BasePart") then
number += 1
print(parts, number)
end
end
How to check how many specific parts are in the workspace, I only want to know how many parts are named “Cube” in the workspace
local numberOfCubes: number = 0
for _, descendant: Instance in workspace:GetDescendants() do
if descendant.Name ~= "Cube" or not descendant:IsA("BasePart") then
continue
end
numberOfCubes += 1
end
print(`number of cubes: {numberOfCubes}`)
This will include any BaseParts named “Cube”. If you only want to include parts of the Part class, change “BasePart” to “Part”.
may i ask how is this useful for everything other than flooding the output and console
or am i at the wrong place
This could be applied to something like a loading screen from what I understand