How to total parts with a specific name in the workspace

Hello, i was recently wondering how i could make a script that totals all the parts in the workspace with a specific name

for example it can be used to show the number of parts called “table” in a gui text label on the players screen

I plan to use this to calculate a percentage of objects that have been deleted or missing.

local count = 0

for i, v in pairs(workspace:GetDescendants()) do
	if v.Name == "" then --change to name of part
		count += 1
	end
end

print(count)
1 Like

Thank you very much. Ill use this right away, and let you know how it worked out!

also, i was wondering where i should put this script?

local count = 0

for i, v in pairs(workspace:GetDescendants()) do
	if v.Name == "" then --change to name of part
		count += 1
	end
end

script.Parent.Text = "Number of parts: "..count

This would work as a local script if placed inside the TextLabel.

1 Like