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

Ho do you do math.random but with players? I want to select a random player for the script

Asked by
OFF_S4LE 127
4 years ago

I wan't to select a random player for the script to execute on. How would I do that?

1 answer

Log in to vote
2
Answered by 4 years ago

You can put all the players in a table, then do a math.random. Below is a simple script where it would print a random name every second.

while wait(1) do
    local players = game.Players:GetPlayers() --getting the players
    local person = math.random(1,#players) --getting a number from 1 to the amount of elements in the table
    print(players[person]) --prints the element in that position
end

Hope this helps!

0
ys OFF_S4LE 127 — 4y
Ad

Answer this question