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

How to count certain objects that named Object2?

I have model and In this model I have 10 objects that named "Object1". random of objects gonna have name "Object2". How I can count them all by using something like Model:GetChildren()

1 answer

✓ Accepted answer

First make a for loop and check they're names, then count along with a variable

Use this:

local count = 0

for i, v in pairs(model:GetChildren()) do
	if v.Name == "Object2" then
		count = count + 1
	end
end

3 comments

0

I would reccomend using the # operator as the table can then be used later easily, if needed. Though this works perfectly fine as well.

0

No, not like that. Without using + or --

0

Object2 can back to Object1

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