GetOrderedDataStore Not Working

I am trying to make a global leaderboard but I ran into an issue with GetOrderedDataStore not working. I can’t seem to find what’s wrong with it because it doesn’t raise any errors. I believe that the Data:GetCurrentPage() just isn’t returning anything but I would love to know what you think.

Code
local DataStoreService = game:GetService("DataStoreService")
local DonationDataStore = DataStoreService:GetOrderedDataStore("MyDataStore")


local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = DonationDataStore:GetSortedAsync(false, 5)
		local Page = Data:GetCurrentPage()
		print(Page) -- Returns "{}"
		for Rank, data in ipairs(Page) do
			local isOnLeaderboard = false
  			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))		
			local Donation = data.value
			for _, Player in pairs(game.Players:GetPlayers()) do
				for _, v in pairs(Player.[Path To Scrolling Frame]:GetChildren()) do
					if v:IsA("Frame") and v.PlayerName.Text == userName then
						isOnLeaderboard = true
						break
					end
				end	
			end
			if Donation and isOnLeaderboard == false then
				for _, v in pairs(game.Players:GetPlayers()) do
					local newLeaderboardFrame = script:WaitForChild("Template"):Clone()
					-- Update template text
				end
			end	
		end
	end)
	if not success then
		print(errorMessage)
	end
end

while true do

	for _, i in pairs(game.Players:GetPlayers()) do
		for _, v in pairs(i.PlayerGui.[Path To Scrolling Frame]:GetChildren()) do
			if v.Name == "Template" then
				print(i.Name)
				v:Destroy()
			end
		end
	end
	
	updateLeaderboard()
	print("Updated")
	wait(10)
end

Seriously, thanks so much if you could help :slight_smile:

1 Like

There is no way to get data without setting it first.

I have set it ~ I’m not that brain dead

Code That Sets It
local MyDataStore = game:GetService("DataStoreService"):GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(player)	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local totalKills = Instance.new("IntValue")
	totalKills.Name = "Total Kills"
	totalKills.Parent = leaderstats
	
	local killsData
	
	local success, errorMessage = pcall(function()
		killsData = MyDataStore:GetAsync(player.UserId.."-totalKills")
	end)
	
	if success then
		totalKills.Value = killsData
	else
		warn(errorMessage)
	end
end)

put a string there
Also remove the .

for _, v in pairs(Player["Path To Scrolling Frame"]:GetChildren()) do

That’s not the issue at all. I put [Path To Scrolling Frame] for the sake of posting this on the forum and simplifying things. In conclusion, I have an actual path to my scrolling frame in my actual script.

I’m not seeing any SetAsync() or UpdateAsync() in your code

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errorMessage = pcall(function()
		MyDataStore:SetAsync(player.UserId.."-totalKills",player.leaderstats["Total Kills"].Value)
	end)
	
	if not errorMessage then
		warn(errorMessage)
	end
end)

I’m having no issues with actually saving the stats. I’m having trouble with getting the datastore info in an order. ~ Try reading my original post about my problem

Make sure your game is published, and that the “Enable Studio Access to API Services” option is enabled

image

Thanks for trying to help out but for the last time, I am not having any trouble saving the data in the datastore. As I already said, please read my original problem.

I think data.key is returning player.UserId.. "-totalKills"

Try to put only player.UserId

MyDataStore:SetAsync(player.UserId, player.leaderstats["Total Kills"].Value)

I’ve just tried this in studio and it works perfectly fine, the only thing I can say is make sure your saving to the ordered data store, in the function you use DonationDataStore but in the saving you use MyDataStore