"table.sort()" isn't actually sorting (solved)

I’ve been attempting to sort an array using table.sort(). And sometimes it works, and sometimes it doesn’t (but in a really weird way).

The array I’m sorting is called Times. The exact code that produces the output (shown in the image below) is:

print(Times) -- Unsorted
print(Times) -- Sorted (supposedly)

As you can see though, the results are not sorted correctly.

Screen Shot 2024-04-02 at 4.14.00 PM

I have no idea what’s causing this…
It runs through about 17+ arrays and uses table.sort() to sort them. And for the first 10 or so, everything works fine, and the resulting array is sorted. But after that, it’s not getting sorted properly.
My initial guess was that I was just sorting too many arrays too fast, but after adding some task.wait(1)'s here and there, the result was the same.
And after running the code multiple times, the sorted (but not really sorted) result was the same…

Am I using table.sort() wrong? Any advice or feedback would be greatly appreciated!

1 Like

Okay just figured out the issue. The items in the table were sorted as strings, not number values (which would explain the not-sorted-but-actually-was-sorted output)…
After using tonumber() to change the type of all the items in the table, everything works fine. Glad it was an easy fix lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.