Table sorts by only first number

I try to sort table from instances names, the problem is that it doesn’t sorted correctly, it only inculdes first number I think, it goes like this 9,8,7,6,5,49,48,47,46,45,44,43,42,41,40,3,39 it sorts like incorrectly.
I tried to make a new table and put only numbers into it, didn’t work as well.
So here is my code:

local Waypoints = ServiceStorage:WaitForChild("Maps"):WaitForChild("Grassland"):WaitForChild("Waypoints"):GetChildren()
local WaypointsName = {}
for i,v in pairs(Waypoints) do
	table.insert(WaypointsName,v.Name)
end
table.sort(WaypointsName,function(a,b)
	return a>b
end)
for i,v in pairs(WaypointsName) do
	print(v)
end

Assuming all names are numbers:

table.sort(WaypointsName, function(a, b)
	return tonumber(a) > tonumber(b)
end)
1 Like

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