I’m making a Teddy Bear Simulator game and wanted to know if there is a better way of returning an array sorted based on a predetermined integer
Here is my code:
function sortedBears()
local bears = TeddyBears:GetChildren()
local nums = {}
local sorted = {}
for k in pairs(bears) do
local bear = ServerStorage.TeddyBears:GetChildren()[k]
nums[k] = bear.Order.Value
end
table.sort(nums)
for k in pairs(bears) do
local bear = ServerStorage.TeddyBears:GetChildren()[k]
for x in pairs(nums) do
if bear.Order.Value == nums[x] then
sorted[x] = bear
end
end
end
return sorted