Making frames appear in Rarity Order

How would i make the frames appear in rarity order (for example: mythic first then legendary then epic etc)

for i,v in pairs(player.swords:GetChildren())  do
		if v.Value > 0 then
			if v.Name~=equippedname then
				local swords = rs:WaitForChild("swords")
				local clonedframe = frame:Clone()
				local rarity = swords:WaitForChild(v.Name).Rarity.Value

				if rarity == "Common" then
				elseif rarity == "Uncommon" then
				elseif rarity == "Rare" then
				elseif rarity == "Epic" then
				elseif rarity == "Legendary" then
				elseif rarity == "Mythical" then
				clonedframe.UIStroke.RGB.Enabled = true	
				clonedframe.BackgroundColor3 = Color3.new(0.141176, 0.141176, 0.141176) 
				end
				clonedframe.number.Text = v.Value
				clonedframe.name.Text = v.Name
				clonedframe.ImageLabel.Image = swords:WaitForChild(v.Name).ImageLabel.Image
				task.wait()
				if clonedframe.name.Text == "Green" then
					clonedframe.UIStroke.Color = Color3.fromRGB(21, 255, 80)
					clonedframe.name.TextColor3 = Color3.fromRGB(21, 255, 80)
				elseif clonedframe.name.Text == "Pink" then
					clonedframe.UIStroke.Color = Color3.fromRGB(250, 111, 255)
					clonedframe.name.TextColor3 = Color3.fromRGB(250, 111, 255)
				elseif clonedframe.name.Text == "Orange" then
					clonedframe.UIStroke.Color = Color3.fromRGB(255, 133, 26)
					clonedframe.name.TextColor3 = Color3.fromRGB(255, 133, 26)
				elseif clonedframe.name.Text == "Cyan" then
					clonedframe.UIStroke.Color = Color3.fromRGB(26, 244, 255)
					clonedframe.name.TextColor3 = Color3.fromRGB(26, 244, 255)
				elseif clonedframe.name.Text == "Gold" then
					clonedframe.UIStroke.Color = Color3.fromRGB(255, 255, 47)
					clonedframe.name.TextColor3 = Color3.fromRGB(255, 255, 47)
				elseif clonedframe.name.Text == "Purple" then
					clonedframe.UIStroke.Color = Color3.fromRGB(147, 24, 255)
					clonedframe.name.TextColor3 = Color3.fromRGB(147, 24, 255)
				end
				clonedframe.Parent = itemsframe
			end
		end

You can give each rarity a value. You can denote 1 as the lowest rarity and some number >1 is a higher rarity.

Can u write this? I’m kinda confused still

You can act these numbers as weights. The higher the weight it is, the higher the value the rarity has. So you can have something like Common = 1, Rare = 2, etc. You can have this in a table and use table.sort to sort them by order.

is this in a UIGridLayout if so then give the frame a LayoutOrder based on rarity and make sure the SortOrder of the UIGridLayout is LayoutOrder. The script would be :


local RarityIndex = {
	["Mythical"] = 1,
	["Legendary"] = 2,
	["Epic"] = 3,
	["Rare"] = 4,
	["Uncommon"] = 5,
	["Common"] = 6,
}
for i,v in pairs(player.swords:GetChildren())  do
		if v.Value > 0 then
			if v.Name~=equippedname then
				local swords = rs:WaitForChild("swords")
				local clonedframe = frame:Clone()
				local rarity = swords:WaitForChild(v.Name).Rarity.Value

				clonedframe.LayoutOrder = RarityIndex[rarity] -- here is the change

				clonedframe.UIStroke.RGB.Enabled = true	
				clonedframe.BackgroundColor3 = Color3.new(0.141176, 0.141176, 0.141176) 
				end
				clonedframe.number.Text = v.Value
				clonedframe.name.Text = v.Name
				clonedframe.ImageLabel.Image = swords:WaitForChild(v.Name).ImageLabel.Image
				task.wait()
				if clonedframe.name.Text == "Green" then
					clonedframe.UIStroke.Color = Color3.fromRGB(21, 255, 80)
					clonedframe.name.TextColor3 = Color3.fromRGB(21, 255, 80)
				elseif clonedframe.name.Text == "Pink" then
					clonedframe.UIStroke.Color = Color3.fromRGB(250, 111, 255)
					clonedframe.name.TextColor3 = Color3.fromRGB(250, 111, 255)
				elseif clonedframe.name.Text == "Orange" then
					clonedframe.UIStroke.Color = Color3.fromRGB(255, 133, 26)
					clonedframe.name.TextColor3 = Color3.fromRGB(255, 133, 26)
				elseif clonedframe.name.Text == "Cyan" then
					clonedframe.UIStroke.Color = Color3.fromRGB(26, 244, 255)
					clonedframe.name.TextColor3 = Color3.fromRGB(26, 244, 255)
				elseif clonedframe.name.Text == "Gold" then
					clonedframe.UIStroke.Color = Color3.fromRGB(255, 255, 47)
					clonedframe.name.TextColor3 = Color3.fromRGB(255, 255, 47)
				elseif clonedframe.name.Text == "Purple" then
					clonedframe.UIStroke.Color = Color3.fromRGB(147, 24, 255)
					clonedframe.name.TextColor3 = Color3.fromRGB(147, 24, 255)
				end
				clonedframe.Parent = itemsframe
			end
		end
1 Like

Thanks alot! Works just as i wanted it to.

1 Like

I’ve also noticed you’re using a lot of if statements, instead of just using a dictionary.

Code:

local RarityIndex = {
	Mythical = 1,
	Legendary = 2,
	Epic = 3,
	Rare = 4,
	Uncommon = 5,
	Common = 6,
}

local Colors = {
	Green = Color3.fromRGB(21, 255, 80),
	Pink = Color3.fromRGB(250, 111, 255),
	Orange = Color3.fromRGB(255, 133, 26),
	Cyan = Color3.fromRGB(26, 244, 255),
	Gold = Color3.fromRGB(255, 255, 47),
	Purple = Color3.fromRGB(147, 24, 255),
}

for i, v in player.swords:GetChildren() do
	if v.Value <= 0 then
		continue
	end
	
	if v.Name ~= equippedname then
		local swords = rs:WaitForChild("swords")
		local clonedframe = frame:Clone()
		local rarity = swords:WaitForChild(v.Name).Rarity.Value

		clonedframe.LayoutOrder = RarityIndex[rarity] -- here is the change

		clonedframe.UIStroke.RGB.Enabled = true	
		clonedframe.BackgroundColor3 = Color3.new(0.141176, 0.141176, 0.141176) 
	end
	
	clonedframe.number.Text = v.Value
	clonedframe.name.Text = v.Name
	clonedframe.ImageLabel.Image = swords:WaitForChild(v.Name).ImageLabel.Image
	
	task.wait()
	
	local uiColor = Colors[clonedframe.name.Text]
	clonedframe.UIStroke.Color = uiColor
	clonedframe.name.TextColor3 = uiColor
	clonedframe.Parent = itemsframe
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.