I want to make a script like on the darkness game where it chooses a random player and puts them on a certain team how can i do this?
You can also do this in one line.
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
Broken down:
game.Players:GetPlayers()
returns a table of all the players in the game
The []
brackets get something from a table, e.g.
local table = {"apple","banana"} print(table[2]) > banana
math.random(arg1,arg2)
returns a random number between arg1 and arg2
#game.Players:GetPlayers()
gets the number of players in the game (# gets the length of a table)
Using the player we've got, we can put them into a team.
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())] randomPlayer.TeamColor = BrickColor.new("Teams TeamColor here")