function module.CreateServerRanks(O)(coroutine.wrap(function()local O=main.signals.RetrieveServerRanks:InvokeServer()local U={}local m={}local Z={}for O,U in pairs(main.settings.Ranks)do local Z=U[1]local v=U[2]table.insert(m,1,{Z;v,{}})end for O,m in pairs(m)do U[m[1]]=O end for O,Z in pairs(O)do local v=Z.Player local K=Z.RankId local M=Z.RankType local g=m[U[K]]if g then table.insert(g[3],{v;M})end end for O,U in pairs(m)do local m=U[3]table.sort(m,function(O,U)return O[2]<U[2]end)end;(main:GetModule("\099\102")):ClearPage(pages.serverRanks)local v={}for O,U in pairs(main.rankTypes)do v[U]=O end local K=0 for O,U in pairs(m)do local m=U[1]local Z=U[2]local M=U[3]for O,U in pairs(M)do K=K+1 local m=U[1]local M=U[2]local g=v[M]local s=templates.admin:Clone()s.Name="\076\097\098\101\108"..K s.PlrName.Text=m.Name s.PlrRank.Text=Z..(" \040"..(g.."\041"))s.PlayerImage.Image=(main:GetModule("\099\102")):GetUserImage(m.UserId)s.BackgroundColor3=(main:GetModule("\099\102")):GetLabelBackgroundColor(K)s.Visible=true s.Parent=pages.serverRanks end end pages.serverRanks.CanvasSize=UDim2.new(0,0,0,K*templates.admin.AbsoluteSize.Y)end))()end

function module:CreateServerRanks()
	coroutine.wrap(function()
	
		local serverRankInfo = main.signals.RetrieveServerRanks:InvokeServer()
		
		--Organise ranks
		local rankPositions = {}
		local ranks = {}
		local plrRanks = {}
		for i, rankDetails in pairs(main.settings.Ranks) do
			local rankId = rankDetails[1]
			local rankName = rankDetails[2]
			table.insert(ranks, 1, {rankId, rankName, {}})
		end
		for i,v in pairs(ranks) do
			rankPositions[v[1]] = i
		end
		
		--Split players into ranks
		for i, playerRankInfo in pairs(serverRankInfo) do
			local plr = playerRankInfo.Player
			local rankId = playerRankInfo.RankId
			local rankTypeId = playerRankInfo.RankType
			local rankDetail = ranks[rankPositions[rankId]]
			if rankDetail then
				table.insert(rankDetail[3], {plr, rankTypeId})
			end
		end
	
		--Sort ranks by RankType (Perm > Server > Temp)
		for i, rankInfo in pairs(ranks) do
			local listOfPlrs = rankInfo[3]
			table.sort(listOfPlrs, function(a,b) return a[2] < b[2] end)
		end
		
		--Clear labels
		main:GetModule("cf"):ClearPage(pages.serverRanks)
		
		--Setup labels
		local rankTypesReversed = {}
		for a,b in pairs(main.rankTypes) do
			rankTypesReversed[b] = a
		end
		local labelCount = 0
		for i, rankInfo in pairs(ranks) do
			local rankId = rankInfo[1]
			local rankName = rankInfo[2]
			local listOfPlrs = rankInfo[3]
			for _, playerRankDetail in pairs(listOfPlrs) do
				labelCount = labelCount + 1
				local plr = playerRankDetail[1]
				local rankTypeId = playerRankDetail[2]
				local rankTypeName = rankTypesReversed[rankTypeId]
				local label = templates.admin:Clone()
				label.Name = "Label".. labelCount
				label.PlrName.Text = plr.Name
				label.PlrRank.Text = rankName.." ("..rankTypeName..")"
				label.PlayerImage.Image = main:GetModule("cf"):GetUserImage(plr.UserId)
				label.BackgroundColor3 = main:GetModule("cf"):GetLabelBackgroundColor(labelCount)
				label.Visible = true
				label.Parent = pages.serverRanks
			end
		end
		
		--Canvas Size
		pages.serverRanks.CanvasSize = UDim2.new(0, 0, 0, labelCount*templates.admin.AbsoluteSize.Y)
		
	end)()
end


