Why are these teams not creating properly?

I have a portion in this game where it creates a team for each group ID that’s in the table. But it doesn’t properly assign the values to some, but others it does?

The Code:

local groups = {

	6682673, -- Main Group
	6683560, -- SCD
	6848288, -- MD
	6848248, -- FEA
	6812894, -- Ethics
	6756547, -- MTF
	6683202, -- ISD
	6756651, -- IA
	6683107, -- SD
	9849559, -- CI
	6684090, -- AD
	9740326, -- R1
	6938442, -- E&T

}

local groupcolors = {

	BrickColor.new("White"), -- Main Group
	BrickColor.new("Cyan"), -- SCD
	BrickColor.new("Persimmon"), -- MD
	BrickColor.new("Toothpaste"), -- FEA
	BrickColor.new("Magenta"), -- Ethics
	BrickColor.new("Navy blue"), -- MTF
	BrickColor.new("Bright red"), -- ISD
	BrickColor.new("Forest green"), -- IA
	BrickColor.new("Mediun stone grey"), -- SD
	BrickColor.new("Really black"), -- CI
	BrickColor.new("Dark stone grey"), -- AD
	BrickColor.new("Royal purple"), -- R1
	BrickColor.new("New Yeller"), -- E&T

}

	for a, v in pairs(groups) do
		
		local newteam = Instance.new("Team")

		newteam.Parent = game.Teams
		newteam.Name = gs:GetGroupInfoAsync(v).Name
		newteam.TeamColor = groupcolors[a]
		newteam.AutoAssignable = false
		
		wait(0.1)

	end

Why is this happening???

EDIT: It works fine in studio, but only when playing an actual game it does this…

I got it to work. Lemme know if it works for you.

local gs = game:GetService("GroupService")

local groups = {

	6682673, -- Main Group
	6683560, -- SCD
	6848288, -- MD
	6848248, -- FEA
	6812894, -- Ethics
	6756547, -- MTF
	6683202, -- ISD
	6756651, -- IA
	6683107, -- SD
	9849559, -- CI
	6684090, -- AD
	9740326, -- R1
	6938442, -- E&T

}

local groupcolors = {

	BrickColor.new("White"), -- Main Group
	BrickColor.new("Cyan"), -- SCD
	BrickColor.new("Persimmon"), -- MD
	BrickColor.new("Toothpaste"), -- FEA
	BrickColor.new("Magenta"), -- Ethics
	BrickColor.new("Navy blue"), -- MTF
	BrickColor.new("Bright red"), -- ISD
	BrickColor.new("Forest green"), -- IA
	BrickColor.new("Mediun stone grey"), -- SD
	BrickColor.new("Really black"), -- CI
	BrickColor.new("Dark stone grey"), -- AD
	BrickColor.new("Royal purple"), -- R1
	BrickColor.new("New Yeller"), -- E&T

}


for a, v in pairs(groups) do
	local newteam = Instance.new("Team")
	local name = gs:GetGroupInfoAsync(v).Name

	newteam.Parent = game.Teams
	newteam.TeamColor = groupcolors[a]
	newteam.AutoAssignable = false
	newteam.Name = name

	wait(0.1)
end

Set the parent last.

	for a, v in pairs(groups) do
		
		local newteam = Instance.new("Team")

		newteam.Name = gs:GetGroupInfoAsync(v).Name
		newteam.TeamColor = groupcolors[a]
		newteam.AutoAssignable = false

		newteam.Parent = game.Teams

		wait(0.1)

	end

The issue is that when there is latency (like on a live server), the creation of the team replicates separately from all of the properties. The CoreGui builds a label for the team before receiving the property changes but does not get a chance to hook up its listeners for changes to the properties before the changes arrive; as a result, they get missed.

If you assign the Parent property last, all of this information comes over in one packet and is processed as intended.

2 Likes

Thank you so much, this makes a ton of sense. I don’t know why I didn’t think of it sooner haha.

1 Like