2 Teams with the Same Name

When I do /assign it’s makes to “Team 1”:
image

Script:

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")


local GroupId = 12212248
local MinRank = 42
local prefix = "/"

local MaxTeamSize = 2

local TeamsTable = {}

local Colors = {BrickColor.new("Baby blue"), BrickColor.new("Pastel green"), BrickColor.new("Pastel orange"), BrickColor.new("Pastel yellow"), BrickColor.new("Pastel blue-green"), BrickColor.new("Pastel light blue"), BrickColor.new("Pastel violet")}

local function CreateTeams()
	local TeamsGenerated = 0
	local AmountOfPlayers = #Players:GetPlayers()
	local TeamsRequired = math.ceil(AmountOfPlayers / MaxTeamSize + 0.5) 
	print(TeamsRequired)
	for count = 1,TeamsRequired do
		TeamsGenerated += 1
		local TeamCreated = Instance.new("Team")
		TeamCreated.Name = "Team " ..TeamsGenerated
		TeamCreated.TeamColor = Colors[math.random(1, #Colors)]
		TeamCreated.AutoAssignable = false
		TeamCreated.Parent = Teams
		table.insert(TeamsTable, 0)
	end
end


local function AssignTeams()
	local CurrentTeamToAddTo = 1
	for i,v in ipairs(Players:GetChildren()) do
		local TeamFound = game:GetService("Teams")["Team " ..CurrentTeamToAddTo]
		if #TeamFound:GetPlayers() >= MaxTeamSize then 
			CurrentTeamToAddTo = CurrentTeamToAddTo +1
			print(CurrentTeamToAddTo)
			local NextTeam = game:GetService("Teams")["Team " ..CurrentTeamToAddTo]
			print(NextTeam.Name)
			print(v.Name)
			v.Team = NextTeam
		else
			print(v.Name)
			v.Team = TeamFound
		end
	end
	local FinalCheck = game:GetService("Teams")["Team " ..CurrentTeamToAddTo +1]
	print()
	if #FinalCheck:GetPlayers() <= 0  then
		FinalCheck:Destroy()
	end
end


game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(GroupId) >= MinRank then
		Player.Chatted:Connect(function(msg)
			if msg == prefix.. "assign" then
				CreateTeams()
				AssignTeams()
			end
		end)
	end
end)

Do you already have Team 1 team?

I just attempted to run this script in game, with 2 players - Everything worked.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.