✓ Accepted answer
Well, if you add i, you're adding the index of that specific table of children.
Let's say the hierarchy looks like this (pretend it makes logical sense; the parenthesis and numbers is the number actually added to your variable):
Part (+1)
Part (+1)
Part (+2)
Part (+1)
Part (+2)
Part (+3)
Part (+3)
Part (+4)
Part (+1)
Part (+2)
Part (+1)
Part (+5)
Basically doing your function is like doing this:
1 + 1 + 2 + 1 + 2 + 3 + 3 + 4 + 1 + 2 + 1 + 5, which equals 26, which clearly there are actually only 12.
Now, let's look at what happens if it doesn't find a "Part" like your code looks for, assuming this is the exact order it searches the children in:
Part (+1)
Part (+1)
Model
Part (+3)
Part (+1)
Part (+2)
Model
Part (+4)
Part (+4)
Part (+5)
Part (+1)
Model
Part (+3)
Model
Part (+2)
Part (+6)
Basically doing your function is like doing this:
1 + 1 + 3 + 1 + 2 + 4 + 4 + 5 + 1 + 3 + 2 + 6, which equals 33, which clearly there are actually 12 parts, still.
Conclusion: So, just stick with + 1 instead of + i to make a part counter to get the correct count.
Hint: If you want to get parts, use :isA("BasePart") instead of :isA("Part") because ALL types of bricks are BasePart.
12 comments
So, its gathering a random amount of numbers from the Parts?
It's not random. It depends all on how many children each item has inside it.
I hope this isn't too confusing.
Ah, I see, it's kind of like labeling them all, like in your explanation its doing 'Part #1' and 'Part #2', and its counting the numbers '#1' and '#2', is that right? I'm not too sure, so I'm making sure I'm atleast a bit onTrack. :P
Yeah, that's the simple way of putting it. Except in tables, there are key-value pairs. Typically tables' key is a number, and it represents the location in the table numerically.
I have one more question, I've seen and used 'BasePart' before, but what does it do, or how does it work?
BasePart is just the inherited class of all Bricks. Basically ALL bricks have the same properties of the BasePart class. http://wiki.roblox.com/index.php?title=API:Class/BasePart All these properties, methods, etc. are inherited down to all types of bricks. You may see some familiar ones.
So, it can tell that 'WedgePart' types are Parts too? :o
Yes. WedgePart, SpawnLocation, Seat, Platform, FlagStand, Part, all are BaseParts, even Unions/NegateOperations.
Wow, you've been a big help man. :) I never knew all that before, I feel a bit silly now, haha! Thanks so much man. :)
No problem.
One last thing: http://wiki.roblox.com/index.php?title=API:Class_Reference If you go here, you can see what is considered what. For example, if you look for BasePart, everything under that (and tabbed in) is considered a part of that specific class. As you can see here, EVERYTHING is under "Instance" as everything inherits the Instance properties. So if you use the :isA method on one of those clas