People go into Neutral team instead of blue or red

you can do this :

local Teams = {game.Teams.Red,game.Teams.Blue}
for i,v in pairs(game.Players:GetPlayers()) do
local RandomTeam = Teams[math.random(1,#Teams)]
v.Team = RandomTeam
end

No, i tested it out when i create a team manually it will assign u when u join even when ur alone.

you can still try the code above

you have to put that after setting the parent of the teams.

That works! Thanks. could you explain what ur block of code exactly does so i can learn from it?

Yeah For Sure!

local Teams = {game.Teams.Red,game.Teams.Blue} -- this table contains both teams instances Which is game.Teams.Red,game.Teams.Blue
for i,v in pairs(game.Players:GetPlayers()) do -- looping through all of the players by using for i,v in pairs loop in this case i is the index and v is the value which is our player.
local RandomTeam = Teams[math.random(1,#Teams)] -- selecting a Random Team from the Teams table.
v.Team = RandomTeam -- v which is the player we will set his Team to the random team.
end

Thanks!, 1 last thing. Due to were using math.random will the teams stay even? so for example when theres 10 people that 5 people are red and 5 people are blue and not 7 people red and 3 people blue for example?

they will be chosen randomly, by what you mean do you want them to be like equal?

Yes, like the Autoassignable function does. that teams are always equal. Sorry my english isnt that good.

you can do something like this then

local t = false
local Teams = {game.Teams.Red,game.Teams.Blue}
for i,v in pairs(game.Players:GetPlayers()) do
if t == false then
v.Team = Teams[1]
t = true
else
v.Team = Teams[2]
t = false
end

Could you explain me again what this all does? xD

sure

local t = false -- we create a boolean variable called t
local Teams = {game.Teams.Red,game.Teams.Blue} -- Teams Table
for i,v in pairs(game.Players:GetPlayers()) do -- Looping through all of the players by using for i,v in pairs loop so i is the index and v is the value which is our player.
if t == false then -- Checking if the t is equals to false
v.Team = Teams[1] -- if so the Player's Team will be the first value in the table which is game.Teams.Red
t = true -- we set t to true
else
v.Team = Teams[2] -- we set the player Team to the 2nd value in the table which is game.Teams.Blue
t = false -- we set t to false.
end

this will create a sort of an organization for example it will be like this
lets say that the game has 7 players
it will be like this

  • Red : 1 Blue : 1
  • Red : 2 Blue : 2
  • Red : 3 Blue : 3
  • Red : 4 Blue : 3

Thanks alot!. Would it be possible to also make this able to have 4 teams? (before i start asking again)

yes.
you can also turn this into a function.

local t = 1
local Teams = {game.Teams.Red,game.Teams.Blue,game.Teams.Green,game.Teams.Yellow}
for i,v in pairs(game.Players:GetPlayers()) do
if t == 1 then
v.Team = Teams[1]
t = 2
elseif t == 2 then
v.Team = Teams[2]
t = 3
elseif t == 3 then
v.Team = Teams[3]
t = 4
elseif t == 4 then
v.Team = Teams[4]
t = 1
end

actually here’s a better way

local Teams = {game.Teams.Red,game.Teams.Blue,game.Teams.Green,game.Teams.Yellow}
for i,v in pairs(game.Players:GetPlayers()) do
TeamSelector(v)
end

local t = 1
function TeamSelector(v)
v.Team = Teams[t]
t += 1
if t == 4 then
t = 1
end
end

or

local t = 1
local Teams = {game.Teams.Red,game.Teams.Blue,game.Teams.Green,game.Teams.Yellow}
for i,v in pairs(game.Players:GetPlayers()) do
v.Team = Teams[t]
t += 1
if t == 4 then
t = 1
end
end

Thanks alot, ill look into these. Have a nice day and thanks for helping :slight_smile:

1 Like

np! feel free to ask anything!

1 Like