I want to sort my scrolling frame by the rarity of the item, there is a StringValue that has the rarity in it inside of each item GUI. For some reason, the code that I made has no errors, and it doesn’t work. I am not sure why, what the code basically does is it moves the GUI into 4 different invisible frames to store them, and then it moves the Easy rarity, then Normal, then Hard, then Insane after the previous rarity is done. For some reason, the game just decides to randomly organize them. This is really frustrating and I need help either fixing the code or coming up with other solutions.
-Peter!
This is the code that I used:
script.Parent.Parent.Parent.Changed:Connect(function()
if script.Parent.Parent.Parent.Visible == true then
for i,v in pairs(script.Parent.Parent.Parent.List.ScrollingFrame:GetChildren()) do
if v:FindFirstChild("BadgeId") then
if v.ImageButton.Rarity.Value == "Easy" then
v.Parent = script.Parent.Parent.Parent.List.EasyFrame
end
if v.ImageButton.Rarity.Value == "Normal" then
v.Parent = script.Parent.Parent.Parent.List.NormalFrame
end
if v.ImageButton.Rarity.Value == "Hard" then
v.Parent = script.Parent.Parent.Parent.List.HardFrame
end
if v.ImageButton.Rarity.Value == "Insane" then
v.Parent = script.Parent.Parent.Parent.List.InsaneFrame
end
end
end
for i,v in pairs(script.Parent.Parent.Parent.List.EasyFrame:GetChildren()) do
v.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
end
if #script.Parent.Parent.Parent.List.EasyFrame:GetChildren() == 0 then
for i,v in pairs(script.Parent.Parent.Parent.List.NormalFrame:GetChildren()) do
v.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
end
if #script.Parent.Parent.Parent.List.NormalFrame:GetChildren() == 0 then
for i,v in pairs(script.Parent.Parent.Parent.List.HardFrame:GetChildren()) do
v.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
end
if #script.Parent.Parent.Parent.List.HardFrame:GetChildren() == 0 then
for i,v in pairs(script.Parent.Parent.Parent.List.InsaneFrame:GetChildren()) do
v.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
end
end
end
end
end
end)
You could use the LayoutOrder property of the GuiObject(s) that is in the ScrollingFrame and set the SortOrder property of UIGridLayout/UIListLayout to LayoutOrder:
Can you share a screenshot of your ScreenGui instance hierarchy? The UILayout suggestion should and does work. There’s a good chance you’ve made a mistake somewhere.
Ok, I came up witha possible solution. Go through all the easy rarity things, and set their LayoutOrder to their index. Then, for the medium, do their index * 100. Hard * 250, and insane * 500. (index is the i in i, v in pairs()
script.Parent.Parent.Parent.Changed:Connect(function()
if script.Parent.Parent.Parent.Visible == true then
local Easy = {}
local Normal = {}
local Hard = {}
local Insane = {}
for i,v in pairs(script.Parent.Parent.Parent.List.ScrollingFrame:GetChildren()) do
if v:FindFirstChild("BadgeId") then
if v.ImageButton.Rarity.Value == "Easy" then
table.insert(Easy,v)
end
if v.ImageButton.Rarity.Value == "Normal" then
table.insert(Normal,v)
end
if v.ImageButton.Rarity.Value == "Hard" then
table.insert(Hard,v)
end
if v.ImageButton.Rarity.Value == "Insane" then
table.insert(Insane,v)
end
end
end
for index, value in ipairs(Easy) do-- for i, v in ipairs() do
value.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
value.LayoutOrder = index
end
for index, value in ipairs(Normal) do-- for i, v in ipairs() do
value.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
value.LayoutOrder = index + 1000
end
for index, value in ipairs(Hard) do-- for i, v in ipairs() do
value.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
value.LayoutOrder = index + 2000
end
for index, value in ipairs(Insane) do-- for i, v in ipairs() do
value.Parent = script.Parent.Parent.Parent.List.ScrollingFrame
value.LayoutOrder = index + 3000
end
end
end)