Dividing players across 3 teams

So i’m making a game where there are 3 types of players, but they’re powers are connected to what team they’re on, how can i go about dividing them equally across the 3 teams when they join? they all join at the same time because of a lobby i have set up


Something like this

teams = {“a”,”b”,”c”}

local assignTeams = function()
    local activePlayers = game.Players:GetPlayers()
    local offset = math.random(#teams) --makes it so that team 2,3 don’t always get the extra players.

    for i=1, #activePlayers do
        local team = teams[(i+offset)%#teams + 1] --always goes team 2, team 3, team 1 repeat.  Offset changes which team it picks first though.
        local rand = math.random(#activePlayers)
        local player = activePlayers[rand] --get a random player so teams aren’t the same every time.  Then remove the the player from the queue since they already have a team.

        --Set players team however you intend to do so.  player is equal to the selected playerObject and team is equal to the data in the teams array for the selected team.

Thanks, i’ll try it out tomorrow