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
 

bad argument #2 to 'random'

Previous Thread :: Next Thread 
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
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
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
13 Mar 2013 03:53 PM
bump.
Report Abuse
velibor is not online. 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
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
13 Mar 2013 03:58 PM
No, there's a # symbol in front of it.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
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 is not online. 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 is not online. 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
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
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 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
13 Mar 2013 04:00 PM
Just

if #game.Players:GetChildren() > 0 then
Report Abuse
velibor is not online. 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 is not online. 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
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