GetRangeAsync returns a blank error if no items are present in stored map

Im making a party system for my game using the MemoryStoreService and I decided to use StoredMaps. I was using the documented example to get all of the items in a map (adapted slightly to meet my needs). It works great except when there are no items in the StoredMap when this occurs it errors. My code is below and the error it produces is also below. Is this a bug with GetRangeAsync or just my code?

function Lobby:PartiesReadAll()
	local function getItems(lowerBound)
		local worked, items = pcall(function()
			return self.Parties:GetRangeAsync(Enum.SortDirection.Ascending, 200, lowerBound)
		end)
		if not worked then
			error(worked)
			--error("Failed to get all parties")
			return getItems()
		end
		return items
	end
	
	local allItems = {}
	local lowerBound = nil
	while true do
		local nextItems = getItems(lowerBound)
		for i, v in pairs(nextItems) do
			table.insert(allItems, v)
		end
		
		if #nextItems < 200 then
			return allItems
		else
			lowerBound = nextItems[#nextItems].key
		end
	end
end

image

1 Like

Your code doesn’t know what to do when it’s empty (I think), cancel the code if the amount if items is 0

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