Help with ordered Datastore - Roblox Scripting Support

I see. Is there not a way to generate or get the JobId before the server is actually made, or does it actually have to be sent from the place?

Well, in short, self is just referring to the current table being put in, it’s basically the same as:

-- This...
function module:Foo()
end
-- ...is exactly the same as this:
function module.Foo(self)
end

-- Same go for these!
module:Foo()
-- Same as above!
module.Foo(module)
1 Like

There is not a way to generate or get the JobId before the server is actually made, you can only get it from inside the running server by game.JobId. I could simply tell the person I want to join the jobid of the server but jobId’s look like this: 45898-3429369-56354-63a-95-49gdskjg (The number is huge lol)

Ahh, that makes a lot more sense now.

I could use this method, but the part I need help with is making it a public table. The best method I found was to use ordered datastores.

Back to the main topic; is there any way you can get the JobId as the server is being created, so you don’t have to return it from the game itself back to the main module?

Right, in order to sync them across for servers, correct? You’re definitely correct, you can do the same thing here with a datastore IIRC. You might have to JSONEncode it though if you end up turning it into a dictionary, but I think tables are serialized through Datastores? I may be wrong though… :thinking:

1 Like

Correct. Asyncing them across servers. And ordered datastores is the closest thing I found to being able to do that.

https://developer.roblox.com/en-us/api-reference/class/OrderedDataStore

So it can only store positive integers? That might be a bit of a problem since you’re trying to store an entire JobId…! Would this pertain more to what you’re trying to achieve?

Hmmm, how would I use globaldatastores? What’s the difference between that and orderedDataStores?

OrderedDataStore is just a build off from it, I believe that it means it’s indexes have to be positive integers, so that it can essentially format it in order, so that it can be sorted in order (correct me if I’m wrong).

I think you could use both honestly, but what makes you so certain that you need to essentially have to order these JobIds? Is there a specific reason as to why you need to order them? Or is it because it was the only thing you could find?

ahhh, no no, I think you right. So if I’m understanding correctly, GlobalDataStore is the same thing but it doesn’t have to be sorted into pages and stuff?

OrderedDataStore only requires that the indexes are sorted in order when you SetAsync, so that when you go to GetSortedAsync, it returns in order(?) Again, please correct me if I’m wrong, but I think you could fundamentally do this with just normal datastores. What stops you from just using datastores as opposed to global datastores? I think if you incorporated it as the way you’re trying with normal datastores, that you’d get the same result in turn.

Wait, so GobalDataStores are just public versions of normal datastores?

All a GlobalDataStore is, in contrast to normal DataStores is that they expose functions for saving and loading data for the DataStoreService. They’re really only useful for getting OrderedDataStores.

In retrospect, they are super similar to DataStores, except the difference being that UpdateAsync & SetAsync (as well as IncrementAsync) functions the value for the set key must be an integer.

1 Like

Oh, that’s confusing lol. Sorry. Hmmm, ok so. Dam, this is hard. Ok, so. All I need to do is make a public datastore basically. How do I do that. I know it is possible lol as people make public leaderboards for their game so you can see who’s the top player and stuff.

What you’re doing is correct though, GlobalDataStore for this would definitely be the way of approaching making global leaderboards, if that’s what we’re talking about now. The more I read the documentation, the more I understand that my initial idea was wrong. It is very confusing to learn new things, I agree. But once you practice them, they’re so much easier and you’ll remember them! :smile:

Anyways, back to what I was saying:
To make a GlobalDataStore, you’ll have to incorporate the GetOrderedDataStore function of DataStoreService, with a custom name, a scope, or ‘global’ as a parameter.

An example being:

local GlobalDataStore = game:GetService("DataStoreService"):GetOrderedDataStore('Global');

After creating a global datastore, you have to get results. To achieve this, you need to make use of the GetSortedAsync function. This should have arguments of the PageSize(how many results per page) - The maximum page size is 100.

1 Like

To furthermore expand:
You can go to the next page of the results by using the AdvanceToNextPageAsync. function!

You can also require the current page you’re on by using the GetCurrentPage function.

Do keep in mind that you can Set / Update / Increment keys just as you would normal datastores.

You can read more about the documentation of GlobalDataStores here!

1 Like

Thanks for your help, let me whip up some code rq…