So i have 6 spawns different colors its a team, is it possible only 2 players can be on the 1 team? ex, 2 players only at Team Green and so on...
thnx :D
local max = 2 function getAllTeams(slotsNeeded) local teamTab = {} for i,v in pairs(Game:GetService('Teams'):GetTeams()) do --For all of the teams, do if getTeamCount(v.TeamColor) < max or not slotsNeeded then --If it has less than 2 members or the argument is false then teamTab[v.TeamColor] = getTeamCount(v.TeamColor) --Add it to the table end end return teamTab end function getRandomIndex(tab) local num = math.random(1,#tab) --Get a random index number local num2 = 0 for i,v in pairs(tab) do num2 = num2 + 1 --Add one to the other number if num2 == num then --If the index number equals the other number return i --Here is our index end end end function getTeamCount(TeamColor) local count = 0 for i,v in pairs(Game.Players:GetPlayers()) do count = v.TeamColor == TeamColor and count + 1 or count --Find the number of players with the TeamColor 'TeamColor' end return count end function fixTeams() for i,v in pairs(Game.Players:GetPlayers()) do --For all of the players if getTeamCount(v.TeamColor) > 2 then --If their team had over 2 players v.TeamColor = getRandomIndex(getAllTeams(true)) --Give them a random Team end end end while wait(0) do fixTeams() end
Untested.