Long if rank checks i need help with shortening it

Include a standalone, bare-bones rbxl file with only the code you want reviewed.

  • Code Review is for reviewing specific parts of your code, and not your whole game.
  • Code Review is intended for improving already-working code. If you need help debugging your code, please use Scripting Support.

Provide an overview of:

  • What does the code do and what are you not satisfied with? the code is way to long and needs to be shorter so i can work with it better
  • What potential improvements have you considered? Shortened code
  • How (specifically) do you want to improve the code? I want neat code not clutter
if game.Players.GetRankInGroup(10886396) == 1 then
	newOverhead.Rank.TextColor3 = Color3.new(0.956863, 0.956863, 0.956863)
end

if game.Players.GetRankInGroup(10886396) == 2 then
	newOverhead.Rank.TextColor3 = Color3.new(0.380392, 0, 0.00784314)
end

if game.Players.GetRankInGroup(10886396) == 3 then
	newOverhead.Rank.TextColor3 = Color3.new(0.890196, 0.890196, 0.890196)
end

if game.Players.GetRankInGroup(10886396) == 4 then
	newOverhead.Rank.TextColor3 = Color3.new(1, 0.333333, 0)
	if game.Players.GetRankInGroup(10886396) then
		if game.Players.GetRankInGroup(10886396) == 5 then
			newOverhead.Rank.TextColor3 = Color3.new(1, 0, 0)
			if game.Players.GetRankInGroup(10886396) == 6 then
				newOverhead.Rank.TextColor3 = Color3.new(0.313725, 0, 0)
				if game.Players.GetRankInGroup(10886396) == 7 then
					newOverhead.Rank.TextColor3 = Color3.new(0, 0, 0.345098)
					if game.Players.GetRankInGroup(10886396) == 8 then
						newOverhead.Rank.TextColor3 = Color3.new(0.517647, 0.52549, 0.00392157)
						if game.Players.GetRankInGroup(10886396) == 9 then
							newOverhead.Rank.TextColor3 = Color3.new(0.00392157, 0.639216, 0.65098)
							if game.Players.GetRankInGroup(10886396) == 11 then
								newOverhead.Rank.TextColor3 = Color3.new(0.0509804, 0.0509804, 0.0509804
									if game.Players.GetRankInGroup(10886396) == 12 then
										newOverhead.Rank.TextColor3 = Color3.new(0.188235, 0.188235, 0.00392157)
										if game.Players.GetRankInGroup(10886396) == 13 then
											newOverhead.Rank.TextColor3 = Color3.new(0, 0, 0)
											if game.Players.GetRankInGroup(10886396) == 253 then
												newOverhead.Rank.TextColor3 = Color3.new(0.101961, 0.101961, 0)
												if game.Players.GetRankInGroup(10886396) == 254 then
													newOverhead.Rank.TextColor3 = Color3.new(0.0862745, 0.054902, 0)
													if game.Players.GetRankInGroup(10886396) == 255 then
														newOverhead.Rank.TextColor3 = Color3.new(0.572549, 0.6, 0.00392157)
													end
												end
											end
										end	end
							end
						end
					end
				end
			end
		end
	end
end

I would suggest a table. Since you’re checking the same group and nothing else you only need to get rank once. I would do it like this:

local rankToColor = {
    [1] = Color3.new(0.956863, 0.956863, 0.956863),
    [2] = Color3.new(0.380392, 0, 0.00784314),
    [3] = Color3.new(0.890196, 0.890196, 0.890196),
    [4] = Color3.new(1, 0.333333, 0),
    [5] = Color3.new(1, 0, 0),
    -- continue
}

Then to actually get the color:

local color = rankToColor[player:GetRankInGroup(10886396)]
if color then
    newOverhead.Rank.TextColor3 = color
end

Assuming the colors are dissimilar from each other, the revised code would be

local tableOfColors = {
	["1"] = Color3.new(0.956863, 0.956863, 0.956863),
	["2"] = Color3.new(0.380392, 0, 0.00784314),
	["3"] = Color3.new(0.890196, 0.890196, 0.890196),
	["4"] = Color3.new(1, 0.333333, 0),
	["5"] = Color3.new(1, 0, 0),
	["6"] = Color3.new(0.313725, 0, 0),
	["7"] = Color3.new(0, 0, 0.345098),
	["8"] = Color3.new(0.517647, 0.52549, 0.00392157),
	["9"] = Color3.new(0.00392157, 0.639216, 0.65098),
	["11"] = Color3.new(0.0509804, 0.0509804, 0.0509804),
	["12"] = Color3.new(0.956863, 0.956863, 0.956863),
	["13"] = Color3.new(0.188235, 0.188235, 0.00392157),
	["253"] = Color3.new(0.101961, 0.101961, 0),
	["254"] = Color3.new(0.0862745, 0.054902, 0),
	["255"] = Color3.new(0.572549, 0.6, 0.00392157)
}

for rank, color in pairs(tableOfColors) do
	if game:GetService("Players")[Player]:GetRankInGroup(10886396) == tonumber(rank) then
	    newOverhead.Rank.TextColor3 = color
	end
end

You can also iterate some numbers between each other because they are consecutive. But I preferred doing this since not all the numbers are consecutively lined up.

Thanks that worked thanks for your help