Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Game isnt choosing a random player?

Asked by
CodeWon 181
3 years ago

So I was making a script to choose a random player, but it wasn't working.

while wait(120) do
    if game.Players:GetChildren() > 1 then
        local randomPlayer = game.Players:GetPlayers()
        [math.random(2, #game.Players:GetPlayers())]

        print(randomPlayer.Name)
    end
end
0
You had the right intentions, but you executed it incorrectly. You want to index a random position in the array determined by ':GetPlayers()': `local RandomPlayer = Players[math.random(1, #Players)]'. Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago
Edited 3 years ago

Almost there!, Try this:

while wait(10) do
    if #game.Players:GetChildren() > 1 then
        local Players = game.Players:GetPlayers()

        randomPlayer = Players [math.random(1, #Players )]

        print(randomPlayer.Name)
    end
end
Ad

Answer this question