So I am making a leaderboard as in a global leaderboard like a part you can see in the game. And I have a pretty basic datastore script for saving the values i want to be saved. But making the leaderboard I ran into an issue where even if the name is correct GetOrderedDataStore doesn’t get the datastore I want… I think it creates a different one but I am not sure.
I think it should get the datastore referenced in the first script but it just doesn’t, so maybe I do not understand what it does?
Anyway, help is appreciated!
:GetDataStore() and :GetOrderedDataStore() are 2 different things. one returns a global datastore and the other an ordered datastore.
the ordered datastore allows you to sort it for thinks like a leaderboard this is the only one you need.
if you have data in the global datastore you can access it and also save it in the ordered datastore to later display it on a leaderboard.
however if you already have lots of data of players in the global datastore it can be a bit tricky to transfer all the data to an ordered datastore.
I’m not exactly sure what your situation is though.
in that case it’s quite simple. you don’t need the global datastore. something like this will do
local DatastoreService = game:GetService("DatastoreService")
local orderedDatastore = DatastoreService:GetOrderedDataStore("Name")
-- adding some data as an example
orderedDatastore:SetAsync("key1", 10)
orderedDatastore:SetAsync("key2", 100)
orderedDatastore:SetAsync("key3", 50)
local sorted = orderedDatastore:GetSortedAsync()
local page1 = sorted:GetCurrentPage() --> list of the top 50
print(page1)
I have not tested this but this should give you an idea of how it works. I would also suggest you read the docs or read some code of open source leaderboard.