Teams getting scrambled with seemingly no explanation?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am having problems with my code for half a year, to put it simple it seems that teams get scrambled like this:

  2. What is the issue? Include screenshots / videos if possible!
    It gets scrambled like this:
    image
    In my code, it should be inserted in the following order:

  • Owner: red
  • Admin: lime
  • Visitor: cyan
local properties = {
		teams = {
			Owner = Instance.new("Team"),
			Admin = Instance.new("Team"),
			Visitor = Instance.new("Team")
		}
	}
	
	properties.teams.Owner.AutoAssignable = false
	properties.teams.Owner.TeamColor = BrickColor.new(255, 0, 0)
	properties.teams.Owner.Name = "Owner"
	properties.teams.Owner.Parent = services.Teams
	
	properties.teams.Admin.AutoAssignable = false
	properties.teams.Admin.TeamColor = BrickColor.new(0, 255, 0)
	properties.teams.Admin.Name = "Admin"
	properties.teams.Admin.Parent = services.Teams
	
	properties.teams.Visitor.AutoAssignable = false
	properties.teams.Visitor.TeamColor = BrickColor.new(2, 230, 255)
	properties.teams.Visitor.Name = "Visitor"
	properties.teams.Visitor.Parent = services.Teams

    --// i do know some improvements can be made in the following code block below
    services.Players.PlayerAdded:Connect(function(joiningPlayer)
		local teamRanked = false
		if ownerid == joiningPlayer.UserId then
			teamRanked = true
			joiningPlayer.Team = properties.teams.Owner
		end
		if not teamRanked then
			for _, v in pairs(admintable) do
				if v == joiningPlayer.UserId then
					teamRanked = true
					joiningPlayer.Team = properties.teams.Admin
				end
			end
		end
		if not teamRanked then
			teamRanked = true
			joiningPlayer.Team = properties.teams.Visitor
		end
	end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Checking the code, which results absolutely nothing

Did you deselect auto assign with the teams?

The auto assign was off by default and that is not the problem I am saying, the problem is how the teams are ordered, in my script it should only have 3 teams and ordered like:

  • Owner: red
  • Admin: lime
  • Visitor: cyan

However when I try to test it it results 4 teams and scrambled order (with colors):
image

I have decided to rewrite the game back into using a module code system, there are no awnsers yet but DET, you may close this topic. (resolved manually)