Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would i make a auto team sorter that sorts players on the lobby team to 2 separate teams?

here is what I have so far

function sortTeams() local Players = game.Players:GetPlayers() local lobbyPlayers = game,Teams.NotinGame:GetPlayers()

I seem to have hit a roadblock and cant figure it out. Thanks!

1 comment

0

Please put the code in a code block :)

1 answer

--###----------[[SERVICES]]----------###--
local Teams = game:GetService("Teams")


local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local LobbyTeam = Teams.NotInGame



--###----------[[FUNCTIONS]]----------###--
local function GetSortedLobby()
	if ((#LobbyTeam % 2) ~= 0) then return end
	--[[ 
		^ Ensures that the original array is of even elements,
		remove to allow odd sorting.
		
		Ceil gives a bias to Team 1, Floor, Team 2.
	]]
	---------------
	local SortedTeams = {
		{},
		{};
	}
	---------------
	for _, Player in pairs(LobbyTeam) do
		---------------
		if (#SortedTeams[1] < (math.ceil(#LobbyTeam / 2))) then
			---------------
			table.insert(SortedTeams[1], Player)
		else
			table.insert(SortedTeams[2], Player)
		end
	end
	---------------
	return SortedTeams
end

1 comment

0

hey, Thanks for asnswering!

This discussion is preserved as it was. New answers, comments, and votes are closed.