OrderedBackups use the format “DATA_STORE_NAME/USER_ID” as the DataStore name for both the GlobalDataStore and the OrderedDataStore. The former provides the actual data given an order while the latter provides the ordering. You first need the latest order (GetSortedAsync, descending order, page size of 1) and then in turn use that to perform a GetAsync on the regular DataStore.
No, I was talking about the DataStore name not the key. The DataStore’s name is the format in quotes for that post. The key to feed for GetAsync is a number you need to find from the OrderedDataStore. If you want to look at actual data you need to follow the steps listed in that post or refer to how OrderedBackups are implemented and translate that into your own code.
Yes. Every player has their own DataStore and OrderedDataStore where their UserId is appended to the DataStore name you give with the DataStore2 constructor DataStore2(STORE_NAME, player). Check the comment at the top of the file.
DataStore2("foobar", colbert2677) --> "foobar/6809102"
^ The function you call ^ The DataStore and OrderedDataStore name
You’re still passing the UserId as a key to the DataStore. A player’s OrderedDataStore contains numbers because you can only save positive unsigned integers to an OrderedDataStore. You need to use the pattern specified by the OrderedBackups implementation if you want a player’s data.
GetSortedAsync, descending, page size of 1 → Get the only item of that page → Get the value of the item you accessed → Feed this to GetAsync on the regular DataStore
You can use the code in the file as reference, the only thing is that it’s designed to work with Promises.
GetAsync will error if you don’t give it a key. I didn’t say you don’t need any parameters, I said you need to get the key from the OrderedDataStore so you can feed it to the GetAsync.
I don’t use DataStore2 because I don’t like the “berezaa method” and I already write my own code for data management so I don’t need the abstractions DS2 provides, so I can’t provide a good answer. That being said, if a leaderboard was your use case you probably should’ve clarified at the beginning (and I should’ve asked as well). There are existing threads you can search through:
Well, the only reason why I’m relying on DataStore2 at the moment is simply because I have have a fear of data loss because I’m saving 6 integers with 6 different datastores, because I can’t save tables to OrderedDataStore, etc.
It’s a lot of yielding, and it might not even save 100% of the time.
Am I just overreacting or do Roblox need to improve their OrderedDataStore stuff, and, how safe is this?
You should probably rethink the way you’re doing your leaderboards, reference developers with existing experiences that can support a large number of leaderboards or look into alternative solutions. That’s way too many DataStores and it also indicates a deeper practice problem of making 6 DataStores authoritative of player data solely for the sake of leaderboards.
OrderedDataStores aren’t necessarily the problem. Since their creation they’ve always been intended as a way to order integers simply. That all being said, because I’ve never done leaderboards in this way, I can’t give you any good advice and I don’t want to pretend that I know this either, so you’ll probably have to seek advice from other developers or look into alternative methods. Sorry about that.
The only other solution would be not to implement it…?
I don’t understand how other games deal with this since you say “that’s way too many”.
You should probably rethink the way you’re doing your leaderboards, reference developers with existing experiences that can support a large number of leaderboards or look into alternative solutions.
Well in my opinion it would be the problem here, I could instead just save everything to a table with OrderedDataStore if they allowed it, and then sort whatever with Table.Information etc.
I can’t tell you what other solutions are out there either. I don’t want to pretend like I know how other developers are doing it, but 6 DataStores seems excessive, it might not necessarily be.
One thought I do have is that they might be going ahead and creating a sizeable number of OrderedDataStores anyway. If you’re flying under limits then I guess you could do it just fine. Since all budgets scale with player count, it could be feasible to just update an OrderedDataStore alongside a GlobalDataStore every now and again. This assumes you have a stable enough player count.
Custom sorting would be a fix, sure, but OrderedDataStore wasn’t designed with that intent. DataStores are getting listing features in the future so that may effectively supersede OrderedDataStores, but that’s down the line and not any time soon. It’s not really the problem though. You need to figure out how to stitch what’s currently provided into a workable system or create your own (e.g. external application that can manage leaderboards).
I might try having 6 and see how it goes.
And yeah, I could use my own database etc, but if I’m going to have a lot of players it’s most likely not free.
Custom sorting would be a fix, sure, but OrderedDataStore wasn’t designed with that intent.
Are there any risks on doing this, and could you elaborate a bit more on how it’s done?