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: how do you get a random item from a table?

Previous Thread :: Next Thread 
Yuuichikun is not online. Yuuichikun
Joined: 09 Nov 2013
Total Posts: 1
22 Mar 2014 09:57 PM
for example, i tried:

local player1 = math.random(game.Players:GetChildren())

but it doesn't work. how would i do this?
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
22 Mar 2014 09:59 PM
players = game.Players:GetPlayers()

plr = players[math.random(1,#players)]
Report Abuse
tery215 is not online. tery215
Joined: 19 Aug 2009
Total Posts: 3879
22 Mar 2014 09:59 PM
i think this method is optimal


local player1 = game.Players:GetChildren()[math.random(1, game.Players.NumPlayers)]
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
22 Mar 2014 10:15 PM
plrs = game.Players:GetPlayers()

plr = plrs[math.random(1, #plrs)]
print(plr.Name)
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
22 Mar 2014 10:17 PM
"i think this method is optimal


local player1 = game.Players:GetChildren()[math.random(1, game.Players.NumPlayers)]"

Nop. Pointless one.

local player1 = game.Players:GetChildren()[math.random(game.Players.NumPlayers)]
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
22 Mar 2014 10:18 PM
The one I posted is correct.
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