How do i make it so there can only be 1 player in a team at a time?

The title is self explanatory, i want to know how i can make a team that can only have one player at a time.

To join the team, the player needs to touch a part, if the team is empty then that player will join the team, else if there is someone already in it they can’t join.

After the player that was on the team dies or leaves, (i already have a script that changes the player’s team once they die) when the team is empty, it is joinable, that way making it so there can only be one player in the team.

Have all players be put on a default team when they join the game.

Then, you can check if a player is in the team by doing the following:

if (#A_TEAM_NAME:GetPlayers() >= 1) then
    -- There is a player in the team.

Here’s a reference to the function for the Team object: GetPlayers

local part = nil
local team = nil

    local pplayer = game:GetService("Players"):GetPlayerFromCharacter(touch.Parent)
    if pplayer ~= nil and #team:GetPlayers() == 0 then
        pplayer.Team = team

This script checks when a player has touched variable part and tries to add them to team if it is empty.
Both local variables at the top will need to be changed for the script to work properly.

Edit: fixed typo in the script.

1 Like

I’ll try it out, gonna mark as solution because theorycally it should work but in case it doesn’t i’ll come back. Thanks!