I got the Datastore2 all set up for my game. One of the combined values is ‘XP’. How would I make a global leaderboard for that? There’s nothing about ordered data stores on the documentation.
There is no built in way to create leaderboards, you can use normal ordered data stores and simply set the value whenever AfterSave
is called.
Do I have to make a BindToClose
function in DataStore2?
No, DataStore2 creates a BindToClose binding on its own already.
Hmm that’s strange. Why when I shutdown server it doesn’t save my data?
Are you using the most recent version from GitHub?
As stated in the documentation, using the main key anywhere outside of DataStore2.Combine is undefined behavior, and shouldn’t work.
Yes I am, I have just started to use DataStore2
@Kampfkarren Hello I wanna make a global leaderboard where top 10 players will be shown. So I need to get my data ordered from high to low. Can I do that in datastore2?
No. He already told it. (30 chars)
So moving data from datastore2 to normal data store… How do I retrieve the saved value to implement on normal datastore?
I don’t know. I started studying about DataStore2 few hours ago.
okay thanks for info. I start digging more
If you handled your data stores as just using the user ID as the key and nothing else, then you can switch the saving method to Standard as explained in the documentation. Otherwise, you will have to manually retrieve it.
You didn’t tell me the error, and I do not have the time to read all the code you posted, sorry.
You’re not providing anything to the default value of :Get()
, so when you index it on a player with no data, it returns nil.
You need to provide a default value to get, in your case it could just be CreateDatastoreTable().MainOBJValues
.
Does OnUpdate() repeat and repeat if yes then ill make a solution of saving tables
also last question can tables be saved using OnUpdate()
:OnUpdate
expects a function to be passed to it. The function is then called whenever the data store value updates. Kind of like listening for an event. You don’t use it to save things.
also btw no need to @ mention the op of a post since they already get notified of a reply
We are trying to save the session play-time value to a players store when they leave, we are using PlayerRemoving:Connect but its not saving, my guess is that it is saving AFTER Datastore2 does its final save.
I noticed a BindToClose method but cant find any documentation on how it is used. Am I on the right track?
From the sound of it, you should just use :AfterSave
.