Want to stay connected to the Scripting Helpers community and get real-time help? Join the Scripting Helpers Discord Server!
Ad
Log in to vote
0

Is there a way to make that only one player can be in a team,not two or more?

Asked by 3 months ago

Hi there, Is there a way that only one player can go to a different team when S/he joins? So when there is a player in e.g team red,so when someone joins the game,S/he won't be in team red BUT S/he will be in a different team,e.g blue team.

Hope I was specific enough.

Best Regards, |Bob-ThisIsTheBetName18|

3 answers

Log in to vote
0
Answered by 3 months ago

You can have a script check how many players are in a specific team and when there's more then one person it teams the person to something else.

Ad
Log in to vote
0
Answered by 3 months ago

If you own a group (which I don't think you do) then you can tell the script to check if one person (like a leader of the group) is in a section of the group. Otherwise, ignore my advice.

Log in to vote
0
Answered by
kingdom5 3643 Snack Break
3 months ago

The team instance now has events and functions to be able to find who is in that team.

One approach would be to use its PlayerRemoved to add itself back into a list when the player leaves.

Another option would be to look through each team and find one which does not have any players by using GetPlayers.

Example function:-

-- returns the team or false if no team is found with 0 players
local function getTeam()
    for _, team in pairs(game:GetService('Teams')) do -- look through each team
        if #team:GetPlayers() == 0 then  -- check if there are no player
            return team
        end
    end
    -- no team found with 0 players
    return false
end

There are a different ways of doing this type of thing so use the appreach that best suits your needs. I hope this helps.

Answer this question