generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: :GetChildren()

Previous Thread :: Next Thread 
AStoryUntold is not online. AStoryUntold
Joined: 09 Mar 2013
Total Posts: 237
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
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
04 Jul 2016 02:44 PM
omg Narwhale..


@OP

#model:GetChildren()
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
04 Jul 2016 02:44 PM
warspy stop making me feel irrelevant to this entire thread

bully


Add 13,000 posts
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
04 Jul 2016 02:46 PM
:( I appreciate you


Friend
Report Abuse
MysticKey is not online. 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
SpeedyJZoel is not online. SpeedyJZoel
Joined: 16 Aug 2010
Total Posts: 2416
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
04 Jul 2016 02:48 PM
@Speedy That's still too much, see my post earlier :)
Report Abuse
MysticKey is not online. 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 is not online. 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 is not online. 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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
04 Jul 2016 03:58 PM
Without context, it's technically best to use mine, since it saves memory (albeit very little)
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
04 Jul 2016 04:04 PM
local NumberOfChildren = #ModelName:GetChildren() print(NumberOfChildren)


-=[ RAP: 345,260 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
cntkillme1 is not online. cntkillme1
Joined: 16 Feb 2012
Total Posts: 592
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 is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
04 Jul 2016 04:08 PM
print(select('#', unpack(model:GetChildren())))

-Fixed unnecessary bug.
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
04 Jul 2016 04:09 PM
mine is best ok ok


Add 13,000 posts
Report Abuse
cntkillme1 is not online. cntkillme1
Joined: 16 Feb 2012
Total Posts: 592
04 Jul 2016 04:09 PM
what bug was that
Report Abuse
digpoe is not online. 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 is not online. 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 is not online. 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
cntkillme1 is not online. cntkillme1
Joined: 16 Feb 2012
Total Posts: 592
04 Jul 2016 04:18 PM
you lost
you all lose
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
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
TheeDeathCaster is not online. TheeDeathCaster
Joined: 19 Jun 2011
Total Posts: 1191
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
04 Jul 2016 04:41 PM
@cnt Of course it saves memory, it's less code is it not?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image