Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to get all scopes of a datastore?

I have a datastore with a scope for each player and a bunch of data in each scope, but I want to create a leaderboard with the data of all users who are stored in the datastore.

Currently I store my data like this: local datastore = GAME_DATA:GetDataStore(PlayerStats, "player-" .. plr.UserId)

How would I go about doing that?

1 comment

0

You would go about doing that with a script.

1 answer

My recommended method for this is GetOrderedDataStore. The arguments you would pass are the key and the scope of the data.

EDIT: Forgot to note that the scope fo the data doesn't have to be specified, and it defaults to global anyways

Using your example it would be

local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("player-" .. plr.UserId)

From here, you would want to use GetSortedAsync on the datastore to get sorted pages for that selected value.

This step would look something like this (please note there are optional arguments and two required arguments. I picked the two that you would probably use, but please read up on the wiki to customize the code I've given)

local OrderedData = DataSTore:GetOrderedData(false, 10)  -- this will get pages of 10 and NOT sort them in descending order

If you do not know how to use the information that is returned in OrderedData, I recommend reading up on Pages, and more specifically DataStorePages

2 comments

0

My datastore isn't accessed with game:GetService("DataStoreService"):GetOrderedDataStore("player-" .. plr.UserId), as I use the datastore "PlayerStats" with scope "player-" .. plr.UserId which is the main problem.

0

I see. In that case I would recommend you saving with the key "player-" .. plr.UserId and using the scope PlayerStats. If you have any data saved I'm sorry but you will lose it. The way you have it set up currently there's a different scope for each player which means it's impossible to get and ordered list

This discussion is preserved as it was. New answers, comments, and votes are closed.