I am using UIGridLayout for an inventory system that sorts the items dynamically like this:
function sort(v)
if v == " Name" then
uiGridLayout.SortOrder = 0
elseif v == " Price (Low)" then
uiGridLayout:SetCustomSortFunction(
function(a,b)
return a.Stat.Price.Value < b.Stat.Price.Value
end
)
uiGridLayout.SortOrder = 1
elseif v == " Price (High)" then
uiGridLayout:SetCustomSortFunction(
function(a,b)
return a.Stat.Price.Value > b.Stat.Price.Value
end
)
uiGridLayout.SortOrder = 1
elseif v == " Amount" then
uiGridLayout:SetCustomSortFunction(
function(a,b)
return tonumber(string.sub(a.Quantity.Text,2)) > tonumber(string.sub(b.Quantity.Text,2))
end
)
uiGridLayout.SortOrder = 1
end
uiGridLayout:ApplyLayout()
end
but whenever I run this function online the game crashes. The weird thing is that it works fine in studio, does not crash and sorts correctly with no errors.
It’s my first time using it so might be just me using it incorrectly. But since it only crashes online and works perfectly fine in studio I don’t know how to fix this.