|
| 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
|
  |
| 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
|
  |
| 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 |
|
|