Help on teams in my game

Sorry if this is in the wrong category.
How do you make it where it automaticly sorts certain people to certain teams

This seems like a technical aspect of scripting. All you want to do is loop through all the players and place them in each team in order. Auto-balancing requires scrambling the table of the players and then placing them back in. Weight system may be utilized for better balancing(i.e. a player’s skill value is based on level and other factors).

Placing them in teams needs to set the player’s team to the team from the Teams service, I think?

I need to set it up where the developers get their own team

If you want certain people to be of a specific team at all times, check its UserId and match it to a list of the developers’ UserIds and override the random team setting(or any other auto-team functionality). To override it, write the functionality before the auto-team and break it after that.

The question is still broad, and we’re on short-hand of information. Could you please elaborate some additional details around the purpose of teams?

There are a variety of ways you could approach this concept.

You could always try to gather all the players up into a table, count the number of elements in the table, divide it by 2, then loop through each player while counting down. If that number reaches 0, place the rest onto another team.

Here’s a rough outline that I would have in mind:

local Players = game:GetService("Players")
local playerTable = {
"Player1",
"Player2",
"Player3",
"Player4"
}

local allElements = #playerTable
local half = allElements / 2

for _, v in ipairs(Players:GetChildren()) do
    if half == 0 or < 1 then
    --start to place players onto the other team
    end

    --Place player into team
    half = half - 1
end

Unsure if this is answer you’re looking for since your post is a bit broad.

I have no auto-team feature as of now. I need it so where any time a certain user joins the game it sets them on a certain rank

Ah, alright. Then it is much simple than that. Apply Players.PlayerAdded a connection to a function which checks each player joined. If the player’s UserId matches any of a list, their team/rank will be set:

local Players = game:GetService("Players")

local VIP_LIST = {} -- let's call it VIP list for now, write the UserIds of each player you want to add to the list

Players.PlayerAdded:Connect(function(player) -- anonymous function
    if table.find(VIP_LIST, player.UserId) then -- this returns an index, if the player is not listed, it returns nil and the if statement is not ran
        -- method of setting rank/team
    end
end)
1 Like