Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to make a 2 player max for each team?

Asked by
sed44 2
9 years ago

Okay, I am making a tycoon that I hope one day will get 1,000 visits. I am a great builder, I have over 10k visits total over all my games (not on each game, overall) Bricksmiths badge ya know, so anyway....

I want to make a spawn, With 2 players max only.

I already made one, BUT, When the player leaves no one else will be able to join the spawn again so can anyone help? Thank you

2 answers

Log in to vote
0
Answered by 9 years ago

I'll write in snippets throughout the course of this answer and will integrate them at the end.

Well, first order of business, we need to be able to find the amount of players on a Team. As you likely know, the players on the team are not immediately accessible from the Team. Therefore, we could create a function as such:

function findOnTeam(color)
    local onteam = {};
    for _,__ in next,game.Players:players'' do
        if(__.TeamColor==color) then rawset(onteam,#onteam+1,__)end;
    end;
    return onteam;
end;

Now, we can find the players on a team. The next step is to hook to the all the Players a Changed event and balance the teams from there.

game.Players.PlayerAdded:connect(function(plr)
    plr.Changed:connect(function(prop)
    if not(prop=='TeamColor') then return end;
    if(#findOnTeam(plr.TeamColor)>1) then plr.TeamColor = BrickColor.new(1) end;
end) end);

Now, to integrate this:

function findOnTeam(color)
    local onteam = {};
    for _,__ in next,game.Players:players'' do
        if(__.TeamColor==color) then rawset(onteam,#onteam+1,__)end;
    end;
    return onteam;
end;
game.Players.PlayerAdded:connect(function(plr)
    plr.Changed:connect(function(prop)
    if not(prop=='TeamColor') then return end;
    if(#findOnTeam(plr.TeamColor)>1) then plr.TeamColor = BrickColor.new(1) end;
end) end);

Now, whenever a player's team changes, this check is performed. If two are already there, it sets them back to the White team.

EDIT: Do to popular demand, I've tabbed the code.

1
Do tab your code correctly... Perci1 4988 — 9y
0
k, did that. KOTwarrior 150 — 9y
0
Btw it is Due to not Do to Mystdar 352 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Make how many teams you want for example

You have 3 teams You can put 6 as the max of players that can join Problem Solved.

Answer this question