|
| 04 Jul 2016 02:28 PM |
How would you find out how many "children" are in a model? What's the easiest way to do this?
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:30 PM |
num = 0
local children = model:GetChildren())
for i,v in pairs(children) do num = num + 1 end
print(num)
Add 13,000 posts |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:44 PM |
omg Narwhale..
@OP
#model:GetChildren() |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:44 PM |
warspy stop making me feel irrelevant to this entire thread
bully
Add 13,000 posts |
|
|
| Report Abuse |
|
|
| |
|
MysticKey
|
  |
| Joined: 28 May 2016 |
| Total Posts: 139 |
|
|
| 04 Jul 2016 02:46 PM |
Why not, if you want it to choose a random brick here's your script local Pick = game.Workspace.MODELNAME:GetChildren() print(Pick[math.random(1,#Pick)])
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:47 PM |
Erm..
That's really too much code lol.
All you do is
local model=workspace.Model:GetChildren()
print(#model)
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:48 PM |
| @Speedy That's still too much, see my post earlier :) |
|
|
| Report Abuse |
|
|
MysticKey
|
  |
| Joined: 28 May 2016 |
| Total Posts: 139 |
|
|
| 04 Jul 2016 02:50 PM |
Speedy that isn't making it choose a random brick it's counting how many bricks there are in the workspace.
|
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Jul 2016 02:53 PM |
| ^That's what OP asked for. The only person discussing random anything is you Mystic |
|
|
| Report Abuse |
|
|
MysticKey
|
  |
| Joined: 28 May 2016 |
| Total Posts: 139 |
|
|
| 04 Jul 2016 03:15 PM |
It's half random and it's still talking about GetChildren(), I know I am off topic I am just extremely bored.
|
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 04 Jul 2016 03:50 PM |
Speedy's method is probably the best. Just doing #model:GetChildren() means that if you need to get the number (or the list of children) at any other point in the script you have to run the GetChildren() method again. Saving the results to a variable means that the only time you will ever need to invoke the method later is if a new child was added or deleted.
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 03:58 PM |
| Without context, it's technically best to use mine, since it saves memory (albeit very little) |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 04:04 PM |
local NumberOfChildren = #ModelName:GetChildren() print(NumberOfChildren)
-=[ RAP: 345,260 || DurstAuric; the narb of ROBLOX ]=- |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 04:07 PM |
| Yours doesn't really save memory in the way you think it does, in reality both methods are virtually the same and the OP is smart enough to turn yours into mudkips, idk why you guys are arguing about this |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 04 Jul 2016 04:08 PM |
print(select('#', unpack(model:GetChildren())))
-Fixed unnecessary bug.
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 04:09 PM |
mine is best ok ok
Add 13,000 posts |
|
|
| Report Abuse |
|
|
| |
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 04 Jul 2016 04:10 PM |
improvement:
print(select(string.char(35), unpack(model:GetChildren())))
-fixes
|
|
|
| Report Abuse |
|
|
mudkip99
|
  |
| Joined: 17 Jun 2008 |
| Total Posts: 3362 |
|
|
| 04 Jul 2016 04:11 PM |
I will concede that yours is the best by far, Narwhal. That's just a level of simplicity and elegance I've never before seen before and am unlikely to ever see again.
|
|
|
| Report Abuse |
|
|
einsteinK
|
  |
| Joined: 22 May 2011 |
| Total Posts: 1015 |
|
|
| 04 Jul 2016 04:14 PM |
Don't mind me winning:
print(table.getn({1,2,3})) --> 3 |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Jul 2016 04:20 PM |
"I will concede that yours is the best by far, Narwhal. That's just a level of simplicity and elegance I've never before seen before and am unlikely to ever see again."
i applaud your praise
and my 100% efficient code
none can surpass my eloquence
Add 13,000 posts |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 04:24 PM |
@OP That would require you to create a variable, and a function to search through the entire model(s):
local NumOfItems = 0 -- Variable used to keep track of how many items have been scanned
fuction AddNumOfItems(obj) -- Function for i, v in pairs(obj:GetChildren()) do -- Loops through table NumOfItems = NumOfItems + 1 -- Adds to variable AddNumOfItems(v) -- Then searches through that child end -- Ends chunk end -- Ends chunk
print('Items found:', NumOfItems) -- Prints how much items there were found
This is just an example though: there're a number of different ways you can accomplish what you're doing! :D
Now, look up in the upper-right corner of your screen, that red box there: that's the door. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 04:41 PM |
| @cnt Of course it saves memory, it's less code is it not? |
|
|
| Report Abuse |
|
|