That’s smart.
But I’d recommend setting LayoutOrder to integer value because if you prices contain fractions Roblox will round them and order of such items will become unpredictable.
So you sort the prices and set LayoutOrder according to price index.
You can use the index as an item’s index in the list later.
As an example:
--!strict
local prices : { number } = { 2.5, 4.5, 0.1, 10, 1 }
local function sort_prices(prices : { number })
table.sort(prices, function(a, b)
return a < b
end)
end
sort_prices(prices)
print(prices)
local function find_price_index(price : number) : number?
return table.find(prices, price)
end
local price_index = find_price_index(4.5)
print("price_index", price_index)
I just wrote a code for this, using table.sort as you said. But didnt use table.find
And… it works
local Prices = {}
local Items = {}
-- Making Prices dictionary and Item array for sorting
for i, item: Model in ItemsFolder:GetChildren() do
Prices[item] = item:GetAttribute("Price")
Items[i] = item
end
-- Sorting items by their prices
table.sort(Items, function(a, b)
return Prices[a] < Prices[b]
end)
-- Making ui with this
for i, model: Model in Models do
-- make button
end