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