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

How to put a limit on teams

Asked by
Lineout 10
10 years ago

I have found that the Teams object does not have a property of "Players", so the counteract that. I just made a table, and a value gets added the that table when a person joins the tables team. My variables for the tables are: BravoPlayers: #_G.BravoPlayerAmount AND AlphaPlayers: #_G.AlphaPlayerAmount . Right now i'm having a *very* hard time finding the formula I need. I have tried things but they don't seem to work. Here's the layout of it tho:

if BravoPlayers {formula}  == AlphaScore + DIFF then
    -- Let player join team
else
    print(" Team has too many players on it, don't join")
end

The diff value = 2, -- If you could make it where you have this into the code. What diff tells it is, say Bravo team and Alpha team have 0 players. Then 2 players join Bravos Team, if another player (3rd player) tried to join the bravo team, it would print("Team has too many players on it, don't join"), therefor making the player have to join Alphas team, so one team does not get WAY too much players

Of course the code above is wrong, but if you can tell me what I need to do, I would be very thankful. If you have any questions about this then just go ahead and post them. Ill try to reply as fast as I can. Thanks for reading (:

1 answer

Log in to vote
0
Answered by 10 years ago
function GetPlayersOnTeam(team)
local count=0;
for i,v in next,Game.Players:GetPlayers() do
if v.TeamColor==team then
count=count+1
end
end
return count;
end

local team1=BrickColor.new("COLOR1")
local max_team1=10

Game.Players.PlayerAdded:connect(function(player)
if GetPlayersOnTeam(team1)<max_team1 then
player.TeamColor=team1
else player.TeamColor=whatever_the_other_team_is
end
end)

If this helped please vote this answer up. :)

0
Thanks for your attempt but it's very.. well unorganised, and I just need the formula . If you could on the for i,v in next part, what does 'next' do? Lineout 10 — 10y
0
It basically just goes through every index in the table. TheGuyWithAShortName 673 — 10y
Ad

Answer this question