Like i am trying to make a camping game(by samsonxvi) so i need to make it choose a random player's https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username= different players also i want it to choose a random players name. SOMEBODY PLS HELP ME!!!
✓ ANSWER ACCEPTED
How do I make the script choose a random player?
1 answer
✓ Accepted answer
You can use :GetPlayers() to get a table of players and then use math.random(smallestNumber, biggestNumber) to pick a random player in that table.
# means number of items.
if you say print(#players) you are printing out the number of players.
here's what the code would look like:
players = game.Players:GetPlayers()
randomPlayer = players[math.random(1,#players)]
keep in mind, if you try running this in a script immediately like this, there won't be any players and you'll get the error: bad argument #2 to 'random' (interval is empty) so make sure you're using the code above when there's actual players in game.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
^ This, but it's pseudorandom. If you want completely random results, create a random seed of tick() using math.randomseed() before using math.random().
false, both are psuedo-random , roblox uses an internal entropy source when you dont provide a seed. A psuedorandom number generation algorithm generally uses a seed, performs some artihmetic on that number, then uses the modulus operator to give the appearance of randomness. In this case, its either you give it a seed or roblox gives it a seed, not one being completely random, and the other not.
Thanks!