GetOrderedDataStore and GetDataStore Problem

I have
local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“Points”)
and I want LeaderBoard
example:
image

I tried this:

local DataStoreService = game:GetService("DataStoreService")
local PointsODS = DataStoreService:GetOrderedDataStore("Points") 
 
local function printTopTenPlayers()
	local isAscending = false
	local pageSize = 10
	local pages = PointsODS:GetSortedAsync(isAscending, pageSize)
	local topTen = pages:GetCurrentPage()
 
	for rank, data in ipairs(topTen) do
		local name = data.key
		local points = data.value
		print(data.key .. " is ranked #" .. rank .. " with " .. data.value .. "points")
	end
 
end
 
PointsODS:SetAsync("Alex", 55)
PointsODS:SetAsync("Charley", 32)
PointsODS:SetAsync("Sydney", 68)
 
printTopTenPlayers()

local DataStore = DataStoreService:GetDataStore("Points")
local abc = DataStore:GetAsync("Alex")
print(DataStore)
print(abc)

but abc is nil
Why

1 Like

I am not sure, but I guess Ordered DataStore and Usual DataStore have difference.
Maybe you should try SetAsync on Usual DataStore and then try to cast Ordered.

are there real players named Alex, Charley or Sydney?

Get Async requires a specific name and in this case there are tons of “Alex”'s around roblox but im guessing you are trying to get your own datastore so usually you get data with your userid or name whatever

image
How I can get userid or name ? its only “Alex”

1 Like

That’s not how that works, you can use any key you want to save data

1 Like

GetOrderedDataStore and GetDataStore not have same value so abc is nil but
local abcd = Points0DS:GetAsync(“Alex”)
print(abcd)
abcd is 55

but I want use GetOrderedDataStore and GetDataStore, How ?

1 Like

Well yeah but it needs to be different for every other player… or am i missing something?


‘Requires unique key for each player’

I saved Value with Getdatastore but I need use GetOrderedDataStore
How I can use with GetOrderedDataStore and GetDataStore

1 Like

I have saved a lot of things with GetDataStore and there is a Power value among what I saved and I will use it to make Leaderboard, but to do Leaderboard, I need to use GetOrderedDataStore.

I dont know getordereddatastore yet but let me guess the code you put is on the dev hub of ordereddatastore. i think rereading that article should get you started atleast

GetDataStore and GetOrderedDatastore returns a different kind of Datastore. So if you save something in a GlobalDatastore, which is returned by GetDatastore, and you tried to get the data from a OrderedDatastore, which is returned by GetOrderedDatastore, then the data will be nil.

TL;DR: These two methods return different things; they are different type of Datastore as they have unique functions.

1 Like

I already know this, but how can we make transfer GetDataStore value to Value in GetOrderedDataStore?

Use getAsync on your global datastore to get the players previous data → than use SetAsync/UpdateAsync to save that value to the ordered Datastore.

1 Like