Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.