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 |
|
|
|
| 29 Aug 2011 05:52 PM |
local object = objecthere local random = math.random(1, #object:GetChildren())
-Like an __AWESOME__ boss |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 23 Nov 2007 |
| Total Posts: 1703 |
|
|
| 29 Aug 2011 05:53 PM |
Thank you very much Blaze : ).
--Sam3812 |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2011 05:54 PM |
No problem. :)
-Like an __AWESOME__ boss |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 29 Aug 2011 06:02 PM |
@xv - Nope. Go in the command bar, and type:
print(#workspace:getChildren())
-Like an __AWESOME__ boss |
|
|
| Report Abuse |
|
|