LayoutOrder starts from 0 and goes to … whatever number you want it to end up at.
It’s super helpful and I didn’t know that it worked well until a few years into my developing career.
Ultimately, you store the LayoutOrder number (which is “1” in my example) and then transfer that data to the client so that it can create a good UI for the player
In it’s most elementary form, your code could look something like this:
-- Hypothetical data structure
local inventory ={
Item1 = {
Layout = 1
};
Item2 = {
Layout = 3
};
Item3 = {
LayoutOrder = 2
}
}
-- Found in Local Script (GUI handling)
for i, v in pairs(inventory) do
-- Apply sort order here onto GUI object
end
LayoutOrder utilises a low-to-high sort - the lowest number will appear first. In the above code, the GUI would hypothetically display Item1, Item3 and then Item2. It could be of use keeping an array to track the Layout Order.
local tracking = {
"Item1",
"Item3",
"Item2"
}
By using this array you could match the LayoutOrder to the Item’s index.