Hello dear developers, i trying to make the shop item and i use template (template duplicates on items in ReplicatedStorage), and when i opens the shop shop getting randomed the items, how i can sort it by cost value?
--a table containing all the items
local items = game.ReplicatedStorage.Items:GetChildren()
--sorting the items array
table.sort(items, function(a, b)
--Assuming Cost is an attribute of each item
return a:GetAttribute("Cost") < b:GetAttribute("Cost")
end)
for _, item in pairs(items) do
--items will loop and print in sorted order
--parent the items to your frame here
print(item)
end
1 Like