Still doesn’t work. Might just try recoding it all to see if it fixes ;p
Can you add documentation on how to use ODS with this? Or give me the basic run down on how I would do it. Thanks.
You wouldn’t be able to because of how DataStore2 saves internally, apologies.
Ahhh thanks for the clarification I re-read the documentation multiple times thinking I missed something. So would it be alright if I used a separate ODS alongside Datastore2 or would the rates be hit?
As long as you’re smart about using 1 DataStore2 key (or use combined data stores), no.
Alright thanks for the clarification! Also really loving Datastore2
Is it possible to create a leaderboard with DataStore2? Like in games that shows the top 10 "insert action here"ers ?
As I said before, DataStore2 has no functionality like ordered data stores. It’s best to just use normal ordered data stores for that, sorry.
Rip, might leave a leaderboard out then. Thanks for the fast reply.
If you aren’t doing too many data store calls, you can just read players’ data from DataStore2, and save it to a regular ordered data store.
Been using this on a few of my projects, and I have to say it works great. Never had any issues in the few months of development I’ve been doing. Good stuff!
I’m having a small issue here. I’m trying to check to see if there is a cached value and if not it tells the client to do stuff.
Code below
DataStore2.Combine("MasterKey", "Avatar")
local Avatar = DataStore2("Avatar", plr)
if not Avatar:Get({},true) then
print('Player has no avatar data')
game:GetService('ReplicatedStorage').Remotes.RemoteEvents.CustomizeAvatar:FireClient(plr,"New")
end
help is appreciated
Is this really what you want? If you don’t provide a default to Get, it’ll return nil which may be what you want. I don’t see why you’d need to check specifically to see if there’s a cached value in the first place.
To check if its the player’s first time playing by checking if the player has data.
Then just check if the result of :Get() is nil.
thanks
Added a little note at the beginning:
After reading through the implementation, I have a few concerns.
-
Save() does not wrap ‘SetAsync’ in a pcall, so any errors as a result of self.dataStore:SetAsync, or self.orderedDataStore:SetAsync will cause a leak in the DataStoreCache for ‘playerLeaving’, and will also break out of the autosave while loop, disabling auto-save for this player for the remainder of their session.
-
It doesn’t seem like self.beforeInitialGet should be a list - instead it should just be a single registered callback, as currently, only the result of the last iterated callback in self.beforeInitialGet list will be assigned to self.value. Similarly, only the result of the last callback in self.beforeSave will be used as the saved value in DataStore:Save(). Since the order of table iteration is undefined, this is problematic.
-
Most of the useful error/critical messages are only logged via ‘warn’. On a large game with many servers these reports will go almost entirely unseen. It would be useful to add an API for the user to provide an error callback that would be invoked in these cases so that the user could log these errors (to the Analytics/Logging platform of choice).
Let me know if something in my comments is a result of misunderstanding. Other than that, nice work on the module!
I’ll look into this. I’m fine with :Save()
tripping off errors but the PlayerRemoving should wrap it in a pcall.
The auto save code doesn’t work even and is going to be removed.
Good point. Made an issue for it.
Also a good idea, made an issue for it.
Thanks for looking through my code.
One question, how would I go about changing a player’s stats when the player isn’t currently present.
Looking through this, it appears I need a player instance to access the datastore2. Represented here:
local buckStore = DataStore2("BuckStats", plr)
Is there a way I can access the data with just a username or a userId?