0

# How can I make a script choose a random player?

Edited 12 days ago

So I am trying to make a script choose a random player but it is not working! I put

local players = game.Players:GetPlayers()
local player = players[math.random(1,#players)]
print(player)


18:38:06.232 ServerScriptService.Script:3: invalid argument #2 to 'random' (interval is empty)  -  Server  -  Script:3

0

You cant get a random number with an input of 1. If you have one player you can choose to wait or pick that player like i did below.

local players = game.Players:GetPlayers()
local player
if #players == 1 then
player = players[1]
print(player)
else
player = players[math.random(#players)]
print(player)
end