|
| 13 Mar 2013 03:50 PM |
randp=game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
Does anyone see any errors in this line? |
|
|
| Report Abuse |
|
|
| |
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 13 Mar 2013 03:56 PM |
It is not GetChildren..
It is Game.Players.NumPlayers
|
|
|
| Report Abuse |
|
|
|
| 13 Mar 2013 03:58 PM |
| No, there's a # symbol in front of it. |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2013 03:58 PM |
| If the number of players is 0, it will error. Second argument must always be larger or equal to the first. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 03:59 PM |
that's why you should go with:
math.random(#stuff:GetChildren) |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 04:00 PM |
Actually, you should check if there are players, because it would error with:
Interval empty |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2013 04:00 PM |
| Ohh, I guess it errors when the server first starts and there are no players. I'll just add a repeat until loop at the top. Thanks. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 04:00 PM |
Just
if #game.Players:GetChildren() > 0 then |
|
|
| Report Abuse |
|
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 13 Mar 2013 04:01 PM |
p = Game:GetService("Players"):GetChildren() randomp = p[math.random(1, #p)] -- This will return the Index of p
|
|
|
| Report Abuse |
|
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 13 Mar 2013 04:02 PM |
Just check at the PlayerAdded event or you have 2 Players for example..
|
|
|
| Report Abuse |
|
|