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

How can I make a script that chooses one of four players?

Asked by 10 years ago

My game has a max of four players, and I would like to be able for a script to choose one of the four randomly and teleport them to a different game.

Thank you for helping!

1 answer

Log in to vote
0
Answered by 10 years ago

You would do this by using math.random.

To get you started here is some example code:

PlayersTable = game.Players:GetPlayers() -- This creates a table containing all the players

MaxPlayers  =  PlayersTable[math.random(1,#PlayersTable)] -- Randomly selects a player from PlayersTable

ROBLOX Wiki on math.random: http://wiki.roblox.com/index.php?title=Math.random

Ad

Answer this question