Ad
Log in to vote
1

Game isnt choosing a random player?

Asked by
CodeWon 65
1 month 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 6785 — 1mo

1 answer

Log in to vote
0
Answered by
TGazza 799 Moderation Voter
1 month ago
Edited 1 month 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