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
 

math.random(1, number of children)

Previous Thread :: Next Thread 
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
29 Aug 2011 05:51 PM
Okay, so if you see the title, that obviously sounds stupid, what I need though is that, I need a random number between 1 and the number of children of a specified object, so how do I go about obtaining this?

I know of the for loop statement that involves for i = #, but I am not sure how I would incorporate this, can I get any help with this?

Thanks

--Sam3812
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
29 Aug 2011 05:52 PM
local object = objecthere
local random = math.random(1, #object:GetChildren())


-Like an __AWESOME__ boss![my siggy pic](http://t6ak.roblox.com/64a4c92f65fb2f33a4382576efb1a0d6)
Report Abuse
xvgigakid is not online. xvgigakid
Joined: 22 Jun 2008
Total Posts: 4407
29 Aug 2011 05:53 PM
b = game.Workspace:GetChildren()
num = 0

for i = 1, #b do
num = num+1 --For each child add 1.
end

print(num)
Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
29 Aug 2011 05:53 PM
Thank you very much Blaze : ).

--Sam3812
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
29 Aug 2011 05:54 PM
No problem. :)


-Like an __AWESOME__ boss![my siggy pic](http://t6ak.roblox.com/64a4c92f65fb2f33a4382576efb1a0d6)
Report Abuse
xvgigakid is not online. xvgigakid
Joined: 22 Jun 2008
Total Posts: 4407
29 Aug 2011 05:55 PM
@Electric

That wont work.
object:GetChildren() is a Table, Not a number value. Just because you put # infront of it, it wont make a diffrence. Ive tried before, trust me.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
29 Aug 2011 05:57 PM
@xv - # is used to define the number of values in a table, or the length of a string.




-Like an __AWESOME__ boss![my siggy pic](http://t6ak.roblox.com/64a4c92f65fb2f33a4382576efb1a0d6)
Report Abuse
xvgigakid is not online. xvgigakid
Joined: 22 Jun 2008
Total Posts: 4407
29 Aug 2011 06:00 PM
I know that. Ive tried it before but it just did not work with me.

It may have something to do with the diffrent placement. It looked like this.

v = Object:GetChildren()
num = #v
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
29 Aug 2011 06:02 PM
@xv - Nope. Go in the command bar, and type:

print(#workspace:getChildren())


-Like an __AWESOME__ boss![my siggy pic](http://t6ak.roblox.com/64a4c92f65fb2f33a4382576efb1a0d6)
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