Problems with AutoTeaming

I basically have problems with people being put in the wrong teams, using this method, Is there any way to prevent people from being put in the wrong teams?


game.Players.PlayerAdded:Connect(function(player)
	if player:IsInGroup(7809126) then -- Army Command
		if player:GetRankInGroup(7809126) >= 2 then
			player.TeamColor = BrickColor.new("Pastel Blue")
		end
	elseif player:IsInGroup(7809126) then -- Army Staff
		if player:GetRankInGroup(7809126) >= 1 then
			player.TeamColor = BrickColor.new("Laurel green")
		end
	elseif player:IsInGroup(7595951) then -- MATCOM
		if player:GetRankInGroup(7595951) >= 3 then
			player.TeamColor = BrickColor.new("Ghost grey")
		end
	elseif player:IsInGroup(7454731) then -- BCT
		if player:GetRankInGroup(7454731) >= 1 then
			player.TeamColor = BrickColor.new("Sea green")
		end
	elseif player:IsInGroup(7519391) then -- ASOC
		if player:GetRankInGroup(7519391) >= 2 then
			player.TeamColor = BrickColor.new("Cocoa")
		end
	elseif player:IsInGroup(7463672) then -- Forces Command
		if player:GetRankInGroup(7463672) >= 2 then
			player.TeamColor = BrickColor.new("Fawn brown")
		end
	elseif player:IsInGroup(7521390) then -- INSCOM
		if player:GetRankInGroup(7521390) >= 2 then
			player.TeamColor = BrickColor.new("Dark stone grey")
		end
	elseif player:IsInGroup(7506593) then -- MPC
		if player:GetRankInGroup(7506593) >= 2 then
			player.TeamColor = BrickColor.new("Deep blue")
		end
	elseif player:IsInGroup(7463156) then -- TRADOC
		if player:GetRankInGroup(7463156) >= 2 then
			player.TeamColor = BrickColor.new("Cool yellow")
		end
	elseif player:IsInGroup(7454731) then -- Army Personnel
		if player:GetRankInGroup(7454731) >= 2 then
			player.TeamColor = BrickColor.new("Flint")
		end
	end
end)
1 Like

If a statement is true the statement in the if statement will run and nothing else.

1 Like

A big problem I can see with this is that if a person is in more than 1 of the groups you’re checking, they will be assigned to the first condition that is met, even if they should be ranked differently. Try to order the if/elseif statements in rank of prominence, where the most important rolls go first so a player isn’t accidentally placed into a lesser roll.

1 Like

And how can i prevent this from happending then?

2 Likes

Like I said in my last post, reorder the if/elseif statements to check for the most important ranks first.

1 Like