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

Assign Player to Team on Join?

Asked by 4 years ago

There are two teams: Red and Black. When a new player joins, they'll be assigned to the team with the least amount of people.

For instance, if Red has 18 people and Black has 22, then the next player that joins will be assigned to Red. If both teams have the same amount of people then the next player that joins will be assigned to a random one.

I couldn't find anything helpful on this (hence the lack of code), so how would I do this? Thanks for your help :)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Help

I suggest reading up on this: https://developer.roblox.com/en-us/api-reference/function/Team/GetPlayers

Code (Server Sided)

01local Teams = game:GetService("Teams")
02 
03local amountOnRed = 0
04local amountOnBlack = 0
05 
06for i, v in pairs(game.Players:GetChildren()) do
07if v:IsA("Player") then
08if v.Team == "Red" then
09amountOnRed = amountOnRed + 1
10elseif v.Team == "Black" then
11amountOnBlack = amountOnBlack + 1
12end
13end
14end
15 
View all 23 lines...

Conclusion If this helped please mark as a solution and follow my roblox!

0
Also the code might not work properly, as I typed it off the bat, so try to write it in your own words. KadenBloxYT 135 — 4y
Ad

Answer this question