More Efficient Script Group and Rank Auto-assignable Team

Hey everyone, so I found some code from here video and their code seems kinda repetitive. Is there a way I can list a group ID > and multiple or a single rank and be able to do this over and over again for different groups and such? I’m trying to make a team rank only auto-assignable script. I know very little about scripting any help would be nice, thanks.

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(4558154) == 3 then
		plr.TeamColor = BrickColor.new("Br. yellowish orange")
		elseif plr:GetRankInGroup(4558154) == 4 then
			plr.TeamColor = BrickColor.new("Br. yellowish orange")
			elseif plr:GetRankInGroup(4558154) == 2 then
				plr.TeamColor = BrickColor.new("Bright green")
				elseif plr:GetRankInGroup(4558154) == 5 then
					plr.TeamColor = BrickColor.new("Br. yellowish orange")
					elseif plr:GetRankInGroup(4558154) == 7 then
						plr.TeamColor = BrickColor.new("Br. yellowish orange")
						elseif plr:GetRankInGroup(4558154) == 7 then
							plr.TeamColor = BrickColor.new("Br. yellowish orange")
							elseif plr:GetRankInGroup(4558154) == 230 then
								plr.TeamColor = BrickColor.new("Br. yellowish orange")
								elseif plr:GetRankInGroup(4558154) == 231 then
									plr.TeamColor = BrickColor.new("Br. yellowish orange")
									elseif plr:GetRankInGroup(4558154) == 233 then
										plr.TeamColor = BrickColor.new("Dark stone grey")
										elseif plr:GetRankInGroup(4558154) == 237 then
											plr.TeamColor = BrickColor.new("Dark stone grey")
											elseif plr:GetRankInGroup(4558154) == 241 then
												plr.TeamColor = BrickColor.new("Dark stone grey")
												elseif plr:GetRankInGroup(4558154) == 242 then
													plr.TeamColor = BrickColor.new("Dark stone grey")
													elseif plr:GetRankInGroup(4558154) == 244 then
														plr.TeamColor = BrickColor.new("Really red")
														elseif plr:GetRankInGroup(4558154) == 245 then
															plr.TeamColor = BrickColor.new("Really red")
															elseif plr:GetRankInGroup(4558154) == 249 then
																plr.TeamColor = BrickColor.new("Really red")
																elseif plr:GetRankInGroup(4558154) >= 250 then
																	plr.TeamColor = BrickColor.new("Really red")
	end
end)

-- Made by Deadwoodx

You don’t need to create a conditional for every single rank in the group, but just for every team color. For example, it seems that the Really red team is from 244 and up.

game.Players.PlayerAdded:Connect(function(plr)
  if plr:GetRankInGroup(4558154) == 5 then
    plr.TeamColor = BrickColor.new("Bright green")
  elseif plr:GetRankInGroup(4558154) <= 231 then
    plr.TeamColor = BrickColor.new("Br. yellowish orange")
  elseif plr:GetRankInGroup(4558154) <= 242 then
    plr.TeamColor = BrickColor.new("Dark stone grey")
  elseif plr:GetRankInGroup(4558154) <= 255 then
    plr.TeamColor = BrickColor.new("Really red")
  end
end)

If your teams get more complicated, then you can create a dictionary and compare the player’s rank with the values in that dictionary. For example,

local rankToTeam = {
  --["Team color"] = {min, max}
  ["Bright green"] = {5, 5},
  ["Br. yellowish orange"] = {1, 231},
  ["Dark stone grey"] = {232, 242},
  ["Really red"] = {243, 255}
}

game.Players.PlayerAdded:Connect(function(plr)
  for teamColor, range in pairs(rankToTeam) do
    if range[1] <= plr:GetRankInGroup(4558154) and plr:GetRankInGroup(4558154) <= range[2] then
      plr.TeamColor = BrickColor.new(teamColor)
      return
    end
  end
end)
1 Like

You can try doing this, make a server script in ServerScriptService and a ModuleScript (name it “Group”, and set it as child of the script)

Module script:

local Group = {}

Group.Id = 6879220

Group.List = {

[1] = BrickColor.new("Br. yellowish orange");

[254] = BrickColor.new("Br. yellowish orange");

}

return Group

Server script:

local Group = require(script:WaitForChild("Group"))

game.Players.PlayerAdded:Connect(function(Player)
	if Player:IsInGroup(Group.Id) then
		local rank = Player:GetRankInGroup(Group.Id)
		if Group.List[rank] then
			Player.TeamColor = Group.List[rank]
		end
	end
end)
2 Likes

Code is outdated, no longer works.

1 Like