Im trying to get half and half of all the players and put them in seperate teams can anyone help me?

local plrs1 = {}
function Team()
for i, player in pairs(game.Players:GetPlayers()) do
    for i = 1, math.floor(#plrs1/2) do
       table.insert(plrs1, player)
		player.Team = game.Teams.Blue
    	end
	end
end

local plrs = {}
function Team1()
	for i, player in pairs(game.Players:GetPlayers()) do
	if not player == game.Teams.Blue then
       table.insert(plrs, player)
		player.Team = game.Teams.Red
		end
	end
end

2 comments

0

what if there is odd number of players :p

0

then I want it to get as even as possible lets say there are 9 players then it will make a team 4 and then a team of 5