Ordered DataStore issue?

Hi,

I’m having a huge ordered datastore issue apparently… Not that I see anything wrong though.

Script:

local function printTopTenPlayers()
	local isAscending = false
	local pageSize = 1
	local pages = DataStoreService:GetOrderedDataStore("Total Wins"):GetSortedAsync(isAscending, pageSize)
	local topTen = pages:GetCurrentPage()
 
	-- The data in 'topTen' is stored with the index being the index on the page
	-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
	for rank, data in ipairs(topTen) do
		local name = data.key
		local points = data.value
		print(name .. " is ranked #" .. rank .. " with " .. points .. " wins")
	end
 
	-- Potentially load the next page...
	--pages:AdvanceToNextPageAsync()
end
 
-- Display the top ten players
printTopTenPlayers()

How I save:

DataStore_Wins:SetAsync(Player.UserId, Wins.Value)

BUT… Output says otherwise…
Example: My wins value is 100, I joined, changed my value to ex: 200, then left. And when I join it says something like this:

12321 is ranked #2 with 123 wins

Shouldn’t it be userid is ranked #number with value?

So my conclusion is that this does not save what so ever. Which is also weird. Because apparently it NEVER updates.

1 Like
  • Make sure you’re also setting values on the same ordered data store rather than a regular data store with equal name. :GetDataStore(name) returns a different data store than :GetOrderedDataStore(name). You have to call :SetAsync on the corresponding OrderedDataStore.

  • If you’re testing in studio, make sure your game settings allow studio API access.

If none of these are potential issues, mind sharing your data saving code?

3 Likes
PlayerService.PlayerRemoving:Connect(function(Player)
	--if game:GetService("RunService"):IsStudio() then
    --	return
	--end
	--wait(Cooldown)
	local succ1, err1 = pcall(function()
		local Wins = Main_Folder:FindFirstChild(Player.Name):FindFirstChild("Total Wins")
		DataStore_Wins:SetAsync(Player.UserId, Wins.Value)
		local Deaths = Main_Folder:FindFirstChild(Player.Name):FindFirstChild("Total Deaths")
		DataStore_Deaths:SetAsync(Player.UserId, Deaths.Value)
		local Best_Killstreak = Main_Folder:FindFirstChild(Player.Name):FindFirstChild("Best Killstreak")
		DataStore_Killstreak:SetAsync(Player.UserId, Best_Killstreak.Value)
	end)
	if succ1 then
		print("[PlayerRemoving] Saved data for", Player.Name)
	else
		print("[PlayerRemoving] Could not save data for", Player.Name .. ".", err1)
	end	
end)

i am using “deaths” to test, dont mind the rest of the values, really

It saves, but not in the ordered datastore.

Are you acquiring DataStore_Wins through :GetDataStore or :GetOrderedDataStore?

1 Like

GetDataStore

:upside_down_face: gotta change this then

5 Likes

I didnt think that would matter, I’ll try and get back in a bit

Oh my, … I really see how it works now, it’s my fault not seeing it clearer. Thank you!

1 Like