TeamColors = {
Red = BrickColor.new("Bright red"),
Blue = BrickColor.new("Bright blue"),
Yellow = BrickColor.new("Bright yellow"),
Green = BrickColor.new("Bright green"),
Orange = BrickColor.new("Bright orange"),
Teal = BrickColor.new("Teal"),
Purple = BrickColor.new("Royal purple"),
Pink = BrickColor.new("Pink")
} --Max teams: 8
function AddTeams(numberOfTeams)
if type(numberOfTeams) == "number" then
local number = 1
for i,v in pairs(TeamColors) do
if (number > numberOfTeams) then return end
print("Index:" .. i, "Value:" .. tostring(v))
local team = Instance.new("Team", game:WaitForChild("Teams"))
team.Name = tostring(i)
team.TeamColor = v
number = number + 1
end
end
end
AddTeams(3)
--Output:
Index:Pink Value:Pink
Index:Purple Value:Royal purple
Index:Blue Value:Bright blue
The above script add teams to the game. However, when I test out the script, the order is wrong. I wanted the table to be like it is (Red, Blue, Yellow, Green, etc.). Why is it in the wrong order?

3 comments
do you get different results if you change pairs to ipairs?
Nothing really appeared in the output when I changed "pairs" to "ipairs".
Oh now I feel stupid for asking that, it's a dictionary. You can't exactly sort a dictionary into a desired order. There's the problem.