Dividing Players into Teams Leaving the Remainder in another Team

In my game, there are created teams at the start of the game. The available teams are put into a table, TeamsTable, and the available players are put into a table, PlayersTable.
How would I divide the players into x amount of teams, leaving the remainder (if any) into a seperate team?

My Script
for _, Team in pairs (TeamsTable) do
		for i = 1, math.floor(#PlayersTable/#TeamsTable) do--Equation doesn't work
			--Assign players to team here.
		end
	end

Here is a good post that explains, and demonstrates, how to do this very well:

Instead of using math.floor, you could alternately use the modulus( % )operator to get the remainder of the division.

1 Like

also had this problem check this thread out!

Although these solve the problem of initially sorting the players into teams, I’m trying to put the remainder of the players (if the players didn’t divide into the teams equally) into a team that’s meant for remainder players (if any)
@ExcessEnergy
@FerbZides
Didn’t see under the link on Excess’ reply, that solves it, thanks.

1 Like

That’s why I recommended using modulus. If you do #PlayersTable % #TeamsTable, you should get the amount of players that are left over after division.