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
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.
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.