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 » Scripting Helpers
Home Search
 

Re: Pick Out Random Child?

Previous Thread :: Next Thread 
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 06:51 AM
How would you make it so that it picks out a random child out of a model?
EG. I have 5 maps in a model that is in lighting. It goes like this:
Lighting>Maps> All the maps. How would you make it so that it picks out one of the maps randomly and puts it into workspace?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
12 Apr 2012 06:53 AM
local rChild = Game.Lighting.Map:GetChildren()[math.random(1, #game.Lighting.Map:GetChildren()]
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
12 Apr 2012 06:54 AM
maps = game.Lighting:GetChildren()

and than something like this

map = math.random(1, maps)

I just forgot it.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
12 Apr 2012 06:55 AM
Well take MrNicNacs script just with an s at the end of Map like this:


local rChild = Game.Lighting.Maps:GetChildren()[math.random(1, #game.Lighting.Maps:GetChildren()]
Report Abuse
legokid135 is not online. legokid135
Joined: 23 Jan 2009
Total Posts: 1470
12 Apr 2012 07:20 AM
Like MrNicNac said, but if you are using a function to pick a random map, and then indexing the map outside that function you will have to remove the "local".

~ Men are like Bank accounts. Without a lot of money they don’t generate a lot of interest. ~
Report Abuse
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 07:22 AM
Sorry, but i didn't get one word of that. Would the script Cheater gave me work?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
12 Apr 2012 07:23 AM
Ya, MrNicNac wrote "Map" instead of "Maps". And you said the directory is called "Maps".
Report Abuse
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 09:24 AM
Btw i forgot to say. Once it's picked a random map how would you make it so it puts ONLY THAT MAP in workspace?
And renames the map...
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
12 Apr 2012 09:29 AM
>local rChild = Game.Lighting.Map:GetChildren()[math.random(1, #game.Lighting.Map:GetChildren()]


Why not just save the table with children as local variable instead of calling the method twice?
Report Abuse
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 09:32 AM
As usual su8 was no help at all....
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
12 Apr 2012 09:37 AM
>As usual su8 was no help at all....

My post wasn't pointed to you..
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
12 Apr 2012 09:43 AM
MODEL=???
a=MODEL:GetChildren()[math.random(#MODEL:GetChildren())]
Report Abuse
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 10:35 AM
I got the random selection robert,but how do you put that map that was selected into workspace?
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
12 Apr 2012 10:37 AM
a.Parent=workspace
a:MakeJoints()
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
12 Apr 2012 10:39 AM
a=game.Lighting.Maps:GetChildren()[math.random(#game.Lighting.Maps:GetChildren())]
a.Parent.workspace
a:MakeJoints()
Report Abuse
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 10:54 AM
Tyvm....
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
12 Apr 2012 10:56 AM
Lol wow, I messed that up...

a=game.Lighting.Maps:GetChildren()[math.random(#game.Lighting.Maps:GetChildren())]
a.Parent=workspace
a:MakeJoints()
Report Abuse
ChocCookieRaider is not online. ChocCookieRaider
Joined: 10 Mar 2012
Total Posts: 338
12 Apr 2012 11:04 AM
Can i ask what the make joints is for?
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
12 Apr 2012 11:08 AM
It's just so it wont fall apart
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
12 Apr 2012 11:13 AM
If the model we are moving out of lighting and into workspace has any joints in it, in other words, parts that are together without the parts being anchored, then the model will fall apart without that simple bit of code.
Report Abuse
legokid135 is not online. legokid135
Joined: 23 Jan 2009
Total Posts: 1470
12 Apr 2012 11:13 AM
MakeJoints() method does exactly as it says on the tin.

http://wiki.roblox.com/index.php/MakeJoints_(Method)

~ Men are like Bank accounts. Without a lot of money they don’t generate a lot of interest. ~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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