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