GetSortedAsync's IsFinished not returning true on the last page

OrderedDataStore:GetSortedAsync() is not returning true on the last page.
This causes the while loop to run endlessly, causing rate limits.

Expected behavior

Pages.IsFinished to return true when the last page has been reached.

Repro Code

local orderedDS = game:GetService("DataStoreService"):GetOrderedDataStore("TestDS")

orderedDS:SetAsync("Test1", 10)
orderedDS:SetAsync("Test2", 1)
print("setted")

task.wait(5)

local pages = orderedDS:GetSortedAsync(true, 100)

while true do
	local breaking = false

	local page = pages:GetCurrentPage()
	for _, data in ipairs(page) do
		local key:string = data.key
		local exist:number = data.value

		print("key", key)
	end

	if pages.IsFinished then
		-- We've reached the last page of results
		breaking = true
	else
		-- There are more pages of results
		pages:AdvanceToNextPageAsync()
		print("advancing, IsFinished", pages.IsFinished)
	end

	if breaking then
		break
	end
end
5 Likes

I can reproduce this issue using the command bar:

19:58:19.492  Christian_Toney joined live editing session.  -  Studio
19:59:12.332  > game:GetService("DataStoreService"):GetOrderedDataStore("TestStore"):SetAsync("TestKey", 2);   -  Studio
19:59:26.334  > local pages = game:GetService("DataStoreService"):GetOrderedDataStore("TestStore"):GetSortedAsync(true, 1); print(pages.IsFinished) pages:AdvanceToNextPageAsync() print(pages.IsFinished)  -  Studio
19:59:26.492   ▶ false (x2)  -  Edit

This is completely breaking my game right now.

2 Likes

This is breaking my game as well.
Stumbling through it, I’ve come to the same conclusions when trying to figure out why my datastores are breaking.

1 Like