function module.CreateRanks(g)(coroutine.wrap(function()local g=main.signals.RetrieveRanksInfo:InvokeServer()local N=g.PermRanks local f=g.Ranks local j=g.Permissions local P={}local r={}for g,N in pairs(f)do local f=N[1]local j=N[2]table.insert(r,1,{f;j,{}})end for g,N in pairs(r)do P[N[1]]=g end for g,f in pairs(j)do if g=="\111\119\110\101\114"and P[8]then local g=r[P[8]]table.insert(g[3],{main.ownerName,"\079\119\110\101\114",(main:GetModule("\099\102")):GetUserImage(main.ownerId)})elseif g=="\115\112\101\099\105\102\105\099\117\115\101\114\115"then for g,N in pairs(f)do if#g>1 then local f=r[P[N]]local j={g,"\083\112\101\099\105\102\105\099 \085\115\101\114";(main:GetModule("\099\102")):GetUserImage((main:GetModule("\099\102")):GetUserId(g))}table.insert(f[3],j)end end for g,N in pairs(N)do if not N.RemoveRank then local g=r[P[N.Rank]]if g then local f={(main:GetModule("\099\102")):GetName(N.UserId),"\080\101\114\109\082\097\110\107";(main:GetModule("\099\102")):GetUserImage(N.UserId);N}table.insert(g[3],f)end end end elseif g=="\103\097\109\101\112\097\115\115\101\115"then for g,N in pairs(f)do if not(main:GetModule("\099\102")):FindValue(main.products,g)then local f=r[P[N.Rank]]if f then local j={N.Name,"\071\097\109\101\112\097\115\115";N.IconImageAssetId;tonumber(g),N.PriceInRobux}table.insert(f[3],j)end end end elseif g=="\097\115\115\101\116\115"then for g,N in pairs(f)do local f=r[P[N.Rank]]if f then local j={N.Name;"\065\115\115\101\116",(main:GetModule("\099\102")):GetAssetImage(g);tonumber(g);N.PriceInRobux}table.insert(f[3],j)end end elseif g=="\103\114\111\117\112\115"then for g,N in pairs(f)do for f,j in pairs(N.Roles)do if j.Rank then local T=r[P[j.Rank]]if T then local j={N.Name..(" \124 "..f),"\071\114\111\117\112",N.EmblemUrl;tonumber(g)}table.insert(T[3],j)end end end end elseif otherPermissions[g]then local N=otherPermissions[g]local f=j[N[1]]if f>0 then local g=r[P[f]]if g then local f={N[2],N[3];string.upper(string.sub(N[1],1,1))}table.insert(g[3],f)end end end end local T=false if main.pdata.Rank>=(main.commandRanks.permrank or 4)then T=true end;(main:GetModule("\099\102")):ClearPage(pages.ranks)local w=0 for g,N in pairs(r)do local f=N[1]local j=N[2]local P=N[3]w=w+1 local r=templates.rankTitle:Clone()r.Name="\076\097\098\101\108"..w r.RankIdFrame.TextLabel.Text=f r.RankName.Text=j r.Visible=true r.Parent=pages.ranks for g,N in pairs(P)do w=w+1 local f=N[1]local P=N[2]local r=N[3]local z=templates.rankItem:Clone()z.Name="\076\097\098\101\108"..w z.ItemTitle.Text=f z.ItemDesc.Text=P if#tostring(r)==1 then z.ItemIcon.Text=r z.ItemIcon.Visible=true z.ItemImage.Visible=false else if tonumber(r)then r="\114\098\120\097\115\115\101\116\105\100\058\047\047"..r end z.ItemImage.Image=tostring(r)end local h=.7 z.Unlock.Visible=false z.ViewMore.Visible=false if P=="\071\097\109\101\112\097\115\115"or P=="\065\115\115\101\116"then local g=N[4]local T=N[5]z.ItemImage.BackgroundTransparency=1 z.Unlock.Visible=true z.Unlock.MouseButton1Down:Connect(function()buyFrame.ProductName.Text=f buyFrame.ProductImage.Image=r buyFrame.PurchaseToUnlock.TextLabel.Text=j buyFrame.InGame.TextLabel.Text=main.gameName buyFrame.MainButton.Price.Text=(T or 0).." "buyFrame.MainButton.ProductId.Value=g buyFrame.MainButton.ProductType.Value=P;(main:GetModule("\099\102")):ShowWarning("\066\117\121\070\114\097\109\101")end)h=.4 elseif P=="\080\101\114\109\082\097\110\107"then local g=N[4]if T then local N=z.ViewMore N.Visible=true N.MouseButton1Down:Connect(function()(main:GetModule("\099\102")):ShowPermRankedUser({f,g.UserId,g.RankedBy})end)end h=.6 else h=.7 end z.ItemTitle.Size=UDim2.new(h,0,z.ItemTitle.Size.Y.Scale,0)z.ItemDesc.Size=UDim2.new(h,0,z.ItemDesc.Size.Y.Scale,0)z.Visible=true z.Parent=pages.ranks end end if w>=2 then for g=1,2,1 do local N=pages.ranks.Label1 local f=pages.ranks["\076\097\098\101\108"..w]pages.ranks.CanvasSize=UDim2.new(0,0,0,(f.AbsolutePosition.Y+f.AbsoluteSize.Y)-N.AbsolutePosition.Y)end end end))()end
---------------------------------------------------
function module:CreateRanks()
	coroutine.wrap(function()
		local ranksInfo = main.signals.RetrieveRanksInfo:InvokeServer()
		local permRanksInfo = ranksInfo.PermRanks
		local ranksToSort = ranksInfo.Ranks
		local permissions = ranksInfo.Permissions

		--Organise ranks
		local rankPositions = {}
		local ranks = {}
		for i, rankDetails in pairs(ranksToSort) 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

		for pName, pDetails in pairs(permissions) do
			--Owner
			if pName == "owner" and rankPositions[8] then
				local ownerRankDetail = ranks[rankPositions[8]]
				table.insert(
					ownerRankDetail[3],
					{ main.ownerName, "Owner", main:GetModule("cf"):GetUserImage(main.ownerId) }
				)
			--SpecificUsers and PermRanks
			elseif pName == "specificusers" then
				for plrName, rankId in pairs(pDetails) do
					if #plrName > 1 then
						local rankDetail = ranks[rankPositions[rankId]]
						local boxInfo = {
							plrName,
							"Specific User",
							main:GetModule("cf"):GetUserImage(main:GetModule("cf"):GetUserId(plrName)),
						}
						table.insert(rankDetail[3], boxInfo)
					end
				end
				for i, record in pairs(permRanksInfo) do
					if not record.RemoveRank then
						local rankDetail = ranks[rankPositions[record.Rank]]
						if rankDetail then
							local boxInfo = {
								main:GetModule("cf"):GetName(record.UserId),
								"PermRank",
								main:GetModule("cf"):GetUserImage(record.UserId),
								record,
							}
							table.insert(rankDetail[3], boxInfo)
						end
					end
				end
			elseif pName == "gamepasses" then
				--Gamepasses
				for gamepassId, gamepassInfo in pairs(pDetails) do
					if not main:GetModule("cf"):FindValue(main.products, gamepassId) then
						local rankDetail = ranks[rankPositions[gamepassInfo.Rank]]
						if rankDetail then
							local boxInfo = {
								gamepassInfo.Name,
								"Gamepass",
								gamepassInfo.IconImageAssetId,
								tonumber(gamepassId),
								gamepassInfo.PriceInRobux,
							}
							table.insert(rankDetail[3], boxInfo)
						end
					end
				end
			elseif pName == "assets" then
				--Assets
				for assetId, assetInfo in pairs(pDetails) do
					local rankDetail = ranks[rankPositions[assetInfo.Rank]]
					if rankDetail then
						local boxInfo = {
							assetInfo.Name,
							"Asset",
							main:GetModule("cf"):GetAssetImage(assetId),
							tonumber(assetId),
							assetInfo.PriceInRobux,
						}
						table.insert(rankDetail[3], boxInfo)
					end
				end
			elseif pName == "groups" then
				--Groups
				for groupId, groupInfo in pairs(pDetails) do
					for roleName, roleInfo in pairs(groupInfo.Roles) do
						if roleInfo.Rank then
							local rankDetail = ranks[rankPositions[roleInfo.Rank]]
							if rankDetail then
								local boxInfo =
									{ groupInfo.Name .. " | " .. roleName, "Group", groupInfo.EmblemUrl, tonumber(
										groupId
									) }
								table.insert(rankDetail[3], boxInfo)
							end
						end
					end
				end
			elseif otherPermissions[pName] then
				--Other
				local info = otherPermissions[pName]
				local rank = permissions[info[1]]
				if rank > 0 then
					local rankDetail = ranks[rankPositions[rank]]
					if rankDetail then
						local boxInfo = { info[2], info[3], string.upper(string.sub(info[1], 1, 1)) }
						table.insert(rankDetail[3], boxInfo)
					end
				end
			end
		end
		--Can view PermRank menu
		local canModifyPermRanks = false
		if main.pdata.Rank >= (main.commandRanks.permrank or 4) then
			canModifyPermRanks = true
		end

		--Clear labels
		main:GetModule("cf"):ClearPage(pages.ranks)

		--Setup labels
		local labelCount = 0
		for i, v in pairs(ranks) do
			local rankId = v[1]
			local rankName = v[2]
			local boxes = v[3]
			--
			labelCount = labelCount + 1
			local rankTitle = templates.rankTitle:Clone()
			rankTitle.Name = "Label" .. labelCount
			rankTitle.RankIdFrame.TextLabel.Text = rankId
			rankTitle.RankName.Text = rankName
			rankTitle.Visible = true
			rankTitle.Parent = pages.ranks
			--
			for _, boxInfo in pairs(boxes) do
				labelCount = labelCount + 1
				local boxTitle = boxInfo[1]
				local boxDesc = boxInfo[2]
				local boxImage = boxInfo[3]
				local rankItem = templates.rankItem:Clone()
				rankItem.Name = "Label" .. labelCount
				rankItem.ItemTitle.Text = boxTitle
				rankItem.ItemDesc.Text = boxDesc
				if #tostring(boxImage) == 1 then
					rankItem.ItemIcon.Text = boxImage
					rankItem.ItemIcon.Visible = true
					rankItem.ItemImage.Visible = false
				else
					if tonumber(boxImage) then
						boxImage = "rbxassetid://" .. boxImage
					end
					rankItem.ItemImage.Image = tostring(boxImage)
				end
				local xScale = 0.7
				rankItem.Unlock.Visible = false
				rankItem.ViewMore.Visible = false
				if boxDesc == "Gamepass" or boxDesc == "Asset" then
					local productId = boxInfo[4]
					local productPrice = boxInfo[5]
					rankItem.ItemImage.BackgroundTransparency = 1
					rankItem.Unlock.Visible = true
					rankItem.Unlock.MouseButton1Down:Connect(function()
						buyFrame.ProductName.Text = boxTitle
						buyFrame.ProductImage.Image = boxImage
						buyFrame.PurchaseToUnlock.TextLabel.Text = rankName
						buyFrame.InGame.TextLabel.Text = main.gameName
						buyFrame.MainButton.Price.Text = (productPrice or 0) .. " "
						buyFrame.MainButton.ProductId.Value = productId
						buyFrame.MainButton.ProductType.Value = boxDesc
						main:GetModule("cf"):ShowWarning("BuyFrame")
					end)
					xScale = 0.4
				elseif boxDesc == "PermRank" then
					local record = boxInfo[4]
					if canModifyPermRanks then
						local viewMore = rankItem.ViewMore
						viewMore.Visible = true
						viewMore.MouseButton1Down:Connect(function()
							main:GetModule("cf"):ShowPermRankedUser({ boxTitle, record.UserId, record.RankedBy })
						end)
					end
					xScale = 0.6
				else
					xScale = 0.7
				end
				rankItem.ItemTitle.Size = UDim2.new(xScale, 0, rankItem.ItemTitle.Size.Y.Scale, 0)
				rankItem.ItemDesc.Size = UDim2.new(xScale, 0, rankItem.ItemDesc.Size.Y.Scale, 0)
				rankItem.Visible = true
				rankItem.Parent = pages.ranks
			end
		end

		--Canvas Size
		if labelCount >= 2 then
			for i = 1, 2 do
				local firstLabel = pages.ranks["Label1"]
				local finalLabel = pages.ranks["Label" .. labelCount]
				pages.ranks.CanvasSize = UDim2.new(
					0,
					0,
					0,
					(finalLabel.AbsolutePosition.Y + finalLabel.AbsoluteSize.Y - firstLabel.AbsolutePosition.Y)
				)
			end
		end
	end)()
end
