I have
local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“Points”)
and I want LeaderBoard
example:
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)
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
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.