Why are my Ordered Datastores not working?

Currently I am making a World Records leaderboard but my ordered datastores do not seem to be picking up any saved values inside of them (There is because saves works). Is this due to me saving in a different script and then doing leaderboards in a different script? Heres the code I’d much appreciate any help:

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local TimeRecordBoard = game.Workspace.TimeLeaderBoard:WaitForChild("Display"):WaitForChild("WorldRecords")

for i, frame in pairs(TimeRecordBoard.Frames:GetChildren()) do 
	local dataStore = DataStoreService:GetOrderedDataStore(frame.Name)
	local success, errormessage = pcall(function()
		local Data = dataStore:GetSortedAsync(true, 50)
		local Page = Data:GetCurrentPage()
		for rank, data in ipairs(Page) do 
			print("Found a player")
			local Username = Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Time = data.Value
			
			if Time then 
				local newFrame = frame:FindFirstChild("Template"):Clone()
				newFrame.UserName.Text = Username
				newFrame.Rank.Text = "#"..rank
				newFrame.Time.Text = tostring(Time)
				newFrame.Parent = frame
				newFrame.LayoutOrder = rank
				newFrame.Visible = true
				newFrame.Name = Username	
			else 
				print("No time was found")
			end
		end
	end)
	if not success then
		print(errormessage)
	elseif success then 
		print("Succesfully did leadeerboards")
	end
end

Successfully did leaderboards prints 8 times each time showing it’s working for each map. Found a player does not print though even though my saves should be on there.

1 Like

I don’t see you ever saving any data. Am I missing or not seeing something?

I saved the data in another script to the exact same names of the datastores. Saves works just the leaderboard doesn’t pick up that there’s anything in the datastore.

im not certain but i dont think you need to to get current page you can just use the data straight away

I get the page just so I can only have the top 50. I think I will just save the data in this script and see how that works out.

When you’re saving the data, are you still using GetOrderedDataStore() or are you just using GetDataStore()? You need to use SetAsync() on the OrderedDataStore.

1 Like