Most Balanced / Fairest Team Making System

Fast, Simple, Fairest Team Making System

In most competitive games, it can be frustrating to have teams that are such different in skill ranges. This new team-making system can generate the fairest teams possible. Compared to most common methods this is ~24x more accurate and fair (when tested with 40 players and their “power” ranging from 1-30). It is significantly slower, but with 40 people, it still manages to operate in under 0.0005 seconds(V4.0, V5.0 is 0.002), which is still blazing fast. The module has a sensitivity option if you are fine with teams being further apart in power. By default, the sensitivity is 0, which means the module will continue to search until a pair has a difference of 0 between the 2 teams, or if it cannot find something with 0 difference, it will pick the next best option. This module does not use leaderstats instead you decide the players’ power using their leaderstats or a custom formula. Ex. A player’s power could be determined by their level * KDR. Odd teams such as 4v3 will be made if the module is requested with an odd number of players.

This Module comes in 2 options, V4.0 and V5.0, For team making, they function the same. The difference? V4.0 is built to handle 2-12 players. V5.0 runs slower because it extends V4.0 and is able to handle 2-40 players. If your game is guaranteed to have 12 or fewer players, use V4.0. If you will ever have over 12 players, you need V5.0.

How do I install / Use it in my game?

Once downloaded, Place either module in ServerStorage, ReplicatedStorage or ServerScriptStorage, your choice. You can then require the module by using

local module = require(ReplicatedStorage[“TeamMakingSystemV4.0”]) --or [“TeamMakingSystemV5.0”])

The module’s function is called BestMatch. You can use the module by doing:

--TeamA and TeamB are a table of all the players on that team. 
--Diff is the difference in “power” between the 2 teams
local TeamA, TeamB, Diff = module.BestMatch(PlayerTable)

The PlayerTable needs to be a dictionary of the players and their “Power”. The players can be the players name or their player instance.

local PlayerTable = {
["Player1"] = math.random(1,30),
["Player2"] = math.random(1,30),
["Player3"] = math.random(1,30),
["Player4"] = math.random(1,30),
["Player5"] = math.random(1,30)}
-- The players power would be in the place of math.random()

Only one of the modules is required, you DO NOT need both for either to run.
If you are unsure of how to use this module, there is an included demo request script on how to use it.

How does it work?

V4.0

Once requested, the module calculates how many combinations of teams are possible. Using lexicographical order, The module cycles through all of the possible team combinations seeing if a pair of teams fit within the sensitivity. If it finds a pair that fits within the sensitivity, it will break the loop and automatically return that pair as the fairest team. If a pair does not fit in the sensitivity, the pair will be added to a list of options that will be used if no other pairs fit. If no pairs fit the sensitivity, it will cycle through all of the options and return the one with the lowest difference between the two teams.

V5.0

V5.0 has V4.0 built into it. (Process shown in picture below) Once requested it will check if the game has sent more than 10 players, if not then it will use the built-in V4.0 function, if it did, it will continue to break down the table until it’s a table of 10 players or less. Ex. A table of 40 players would be broken down into 4 tables of 10 players. The module then requests the same function as V4.0 and will optimize the 4 tables of 10 players into 8 groups of 5 players. The module then creates a table of the 8 groups and the power of each group. These 8 groups are run through the V4.0 function again simulating 8 players but each “player” is linked back to a table of the actual players. Once the function completed, The two teams of groups are broken down into 2 teams of players. The module then returns these 2 teams and the power difference between them.

What’s Included?

TraditionalTeamMaking - More common, faster, significantly less accurate, available for testing
TeamMakingSystemV4.0
TeamMakingSystemV5.0
Example Req Script - Shows how to use
DataTestScript - Benchmarking, Runs modules 50x, to find averages (time and accuracy)

Place:Forum Team Making Place.rbxl (23.6 KB)

SourceCode
Thanks for Reading / Trying it out! If there are any issues with it, don’t hesitate to DM me here on the Forum.

55 Likes

You did a great job with it! It does exactly what you say it does, i’ll be trying it out on a few games of mine. Keep up the good work!

1 Like

I’m not the best in scripting so i’ll ask you for some help. Any idea on how i could make the players in TeamA be on the Blue Team, and players in TeamB be on the Red Team. Also the list seems to not select the players that are in the game, only the players with the names in the list. Hope you can help.

1 Like

Here is an example. Here we get the players in the game, Insert them into the PlayerTable with their rank as their power, Run the module, then assign the players to each team.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local TeamService = game:GetService("Teams")

local PlayerTable = {}
for i,player in pairs(Players:GetPlayers()) do--Gets Players
	PlayerTable[player] = player.leaderstats.Rank.Value--Inserts Player in to PlayerTable with thier "power"
end

local module = require(ReplicatedStorage["TeamMakingSystemV4.0"])--gets the module
local TeamA,TeamB,Diff = module.BestMatch(PlayerTable)--Runs module

local function SetPlayerTeam(Team,Color)
	for i,Player in pairs(Team) do--Go through all players on that team
		Player.Team = Color--sets the player to that team
	end
end

SetPlayerTeam(TeamA,TeamService.Red)-- Calls function to set people in Team A to Red Team
SetPlayerTeam(TeamB,TeamService.Blue)-- Calls function to set people in Team B to Blue Team
2 Likes

Updated to include the SourceCode for the modules.

1 Like

Thanks, I was looking for a balanced team system. Will use!

1 Like