I want to make this so it doesn't team people to another team that is colored Sand green. I've tried different things such as using or statements on TeamColor == and even duplicating the TeamColor lines and changing white to Sand green.
if #(game.Teams:GetChildren()) > 1 then
local list = {}
local P = game.Players:getChildren()
for i=1, #P do
if P[i].TeamColor == BrickColor.new("White") then
list[#list+1] = P[i]
end
end
local teamList = {}
local teams = game.Teams:getChildren()
for i=1, #teams do
if teams[i].TeamColor ~= BrickColor.new("White") then
teamList[#teamList+1] = teams[i]
end
end
local numPerTeam = (#list/#teamList)
------------------------------------------
math.randomseed( os.time() )
local function shuffleTable( t )
local rand = math.random
assert( t, "shuffleTable() expected a table, got nil" )
local iterations = #t
local j
for i = iterations, 2, -1 do
j = rand(i)
t[i], t[j] = t[j], t[i]
end
end
shuffleTable(list)
------------------------------------------
local num = 1
for i=1, #teamList do
for q=1, numPerTeam do
list[num].TeamColor = teamList[i].TeamColor
num = num + 1
end
end
----------Get the remaining people
local list = {}
local P = game.Players:getChildren()
for i=1, #P do
if P[i].TeamColor == BrickColor.new("White") then
list[#list+1] = P[i]
end
end
script.List:ClearAllChildren()
for i=1, #list do
--list[i].TeamColor = teamList[i].TeamColor
if #teamList > 1 then
local tempList = {}
for q=1, #teamList do --For each team
local TEAM = script.Team:clone()
TEAM.Name = teamList[q].Name
TEAM.Value = teamList[q].TeamColor
for w=1,#P do --Search all players
if P[w].TeamColor == teamList[q].TeamColor then --if the player matches the team then true
TEAM.Count.Value = TEAM.Count.Value + 1
end
end
TEAM.Parent = script.List
end
--local sort_func = function(a,b) return a.tempList[1] > b.tempList[2] end
tempList = script.List:getChildren()
local function compare(a,b)
return a.Count.Value < b.Count.Value
end
table.sort(tempList, compare)
for i=1, #tempList do
print(tempList[i].Name.."..."..tempList[i].Count.Value)
end
list[i].TeamColor = tempList[#tempList].Value
else
list[i].TeamColor = teamList[1].Value
end
end
end
end)

2 comments
Are you just trying to randomize a players team when they join? If so, that script doesent need to be so long.
No, it's a button on a gui to randomize teams. It's part of a holo system.