GetOrderedDataStore not getting the DataStore I want

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.

--script 1
datastoreservice:GetDataStore("Name")

--more code
--script 2
datastoreservice:GetOrderedDataStore("Name")

--more code

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.

1 Like

Okay, but can I somehow access the original data store and use information from it?

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.

1 Like

This is for a game which is indev 0 datastores in that game the test one where I’m making the leaderboard has 1 datastore

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.

You should also add proper pcalls to this.

1 Like

I’ll try something tommorow, I will update this post if it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.