This is simply because you're printing the number of children in the model regardless of what you're checking in the loop. All you need is a simple variable that keeps track of the number of parts with the name "part1" and increment it every time you encounter one with such a name. For example:
local children = model:GetChildren()
local count = 0
for i = 1, #children do
if children[i].Name == "part1" then
count = count + 1
end
end
print(count)
(additionally, it is recommended that you use local variables, because Lua works in such a manner to where local variables are indexed faster - it's just better practice in general too even if the performance is negligible)
1 comment
I tried print(#children[i]), returns a userdata error