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 » Scripters
Home Search
 

Array Help!

Previous Thread :: Next Thread 
AlphaOverflow is not online. AlphaOverflow
Joined: 09 Nov 2016
Total Posts: 592
07 Jan 2017 12:37 PM
Lets say I have an array such as...

local people
{

["Person1"] = 0,
["Person2"] = 0,
["Person3"] = 0,
["Person4"] = 0,
["Person5"] = 0

}

And I want to pick at random 2 keys out of this array.
How would I do this? I have tries in pairs, but it does the whole list...
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
07 Jan 2017 12:39 PM
That's not an array, that's a dictionary. You cannot iterate over a dictionary, therefore you cannot determine random players.

However if you need 2 random players, just say

function ReturnRandomPlayers(num)
local players= game.Players:GetPlayers()
for _,num in next,players do
return players[math.random(1,#players)]
end
end)

local player1,player2 = ReturnRandomPlayers(2)



Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
07 Jan 2017 12:53 PM
Sorry, that code is broken but I can't fix it right now

The problem is in the return- you only do that once, so gather the random players THEN return

will fix when I get back if you still need


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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