I started a war game, I only want 6 players on each team, like if this were to work in a LocalScript..
if game.Teams.TEAMNAME.NumPlayers == 6 and game.Teams.TEAMNAME.PlayerAdded then game.Players.LocalPlayer.Team = "TEAMNAME2" end
PlayerAdded
is the thing I'm not sure about. I don't know if it should be there. I need a better script, because, obviously, this doesn't work. There are gonna be 12 players allowed in the game. 6 each team.
Even the NumPlayers
part I'm worried about, it's maybe not supposed to be there.
The Script Does Not Work
Please help me with this. Thank you.
If you are only allowing 12 people into the game at once, then ROBLOX's default Team sorting will not allow for more than 6 players on any team, so long as the number of players in the server never actually gets above 12.
That said, you have to loop through the Players of a game to get how many are in each Team, as Teams are purely organizational: they don't have any methods of their own, regardless of how useful that may be (which is why most developers will design their own Team system, rather than use ROBLOX's).
local TeamColor1 = BrickColor.new("Bright red") local TeamColor2 = BrickColor.new("Bright blue") --Change these two to reflect your game's TeamColors. function GetTeams() local team1, team2 = {}, {} for _, v in ipairs(Game.Players:GetPlayers()) do if v.TeamColor == TeamColor1 then table.insert(team1, v) elseif v.TeamColor == TeamColor2 then table.insert(team2, v) else error(v.Name .. "'s TeamColor does not match either provided TeamColor.") end end return team1, team2 end Game.Players.PlayerAdded:connect(function(Player) local team1, team2 = GetTeams() if #team1 <= #team2 then Player.TeamColor = TeamColor1 else Player.TeamColor = TeamColor2 end end)
teams = game.GetService("Teams") team1 = teams.Team1 -- just for example, this will be the "Really red" team team2 = teams.Team2 -- and this the "Really blue" game.Players.PlayerAdded:connect(function(player) -- when a player enters team1players = team1:GetChildren() -- get the players in that team team2players = team2:GetChildren() -- same if #team1players > #team2players then -- if team1 has more than team2 player.TeamColor = BrickColor.new("Really blue") -- the player goes to team2 elseif #team1players < #team2players then -- if team2 has more than team1 player.TeamColor = BrickColor.new("Really red") -- the player goes to team1 else -- the teams are equal player.TeamColor = BrickColor.new("Really blue") -- the player goes to team2, or team1 (which one you want, just because they're already balanced) end end)
Observation: players have the TeamColor property, teams are separated in colors.