Create a table containing all the players using GetChildren()
. Then, choose a random player by indexing a random player from that table. Don't forget to remove the chosen players from the table, otherwise they can be chosen twice :
1 | local Players = game.Players:GetChildren() |
4 | ChosenPlayerIndex = math.random(#Players) |
5 | Players [ ChosenPlayer ] .TeamColor = BrickColor.new( "Bright blue" ) |
6 | table.remove(Players, ChosenPlayerIndex) |
(This script is supposed to be placed inside either game.Workspace or game.ServerScriptService, in a normal script)