Back to Library
Utility Nov 22, 2025

Auto Assign Teams

T
by terrorsoul

Assigns players to team 1 or 2 when they join. Based on player id

LUA
function AutoAssignTeam(playerId)
    -- Even IDs = Team 1, Odd IDs = Team 2
    local teamIndex = (playerId % 2) + 1
    
    -- Set the team
    tm.players.SetPlayerTeam(playerId, teamIndex)
end

-- Hook this into the PlayerJoined event
tm.players.OnPlayerJoined.add(AutoAssignTeam)

Discussion

Please log in to post a comment.