How to use DataStore2 - Data Store caching and data loss prevention

Hi, I’m getting reports of some people’s data not saving though I can’t reproduce the issue. I’ve tracked it down to the function OrderedBackups:Set and it has to do with one of the pcalls returning false. There is no difference between the two, so how would I go about debugging this?

One of the pcalls (the one below) I added RankedInfoATFloors:SetAsync(value.userId, value.totalFloors) to, which updates my leaderboards. This has always worked in the past though so I don’t know why it would break for some people. Take a look below:

local success, problem = pcall(function()
	RankedInfoATFloors:SetAsync(value.userId, value.totalFloors)
	self.dataStore:SetAsync(key, value)
end)

The error I’m getting is on line 386 of the main DataStore2 module with “save error! Argument 1 missing or nil”. I found that this error came from calling the OrderedBackups:Set function I mentioned above.

1 Like

I don’t know what line 386 is if you messed with the code yourself (which by the way, means you have to open source your entire fork of the module). I definitely would not recommend editing the original code to begin with, you’d be better off just using AfterSave and setting the ordered data store then.

1 Like

I didn’t modify the original module, I only added the line to the OrderedBackups saving method that saves the data to the leaderboard (does that count as part of the module?). Also, I’m guessing AfterSave is fired after that part in the saving is completed?

1 Like

@Kampfkarren Is it better to call :Get() for every value saved in a DataStore to update the leaderstats and update the UI showing the value too, using FireClient() on OnUpdate
or
should I only call Get() for updating the leaderboard value and using a .Changed Event to detect the values being changed and then update the UI without calling Get again?

Will too many Get calls used like this cause throttling or something?

1 Like

Yes, it does.

Yes, it does.

1 Like

Get() only uses data store methods the first time you call it. Feel free to call it as much as you want.

1 Like

Thanks to Datastore2, my game had not even a single data loss, without Datastore2 I would have kept loosing data each day, now everything is stable, no longer need to restore data for each player. Datastore2 saved me a lot of troubles. Thank you again for making this awesome creation!

2 Likes

@Kampfkarren

Final question,

And Firing an event for every Client each time every value changes using :Get() is a good idea to update UI containing those values? I know OnUpdate exists, but this is to update stats on the Client, which can’t access the module so I can’t require DataStore2 and get the value using Get(), I fire for every Client OnUpdate each time a value changes, won’t this exhaust some sort of limit for firing for every Client?

In the documentation , there was an example showing how whenever a value changed, using OnUpdate an event was fired for the player using a function CallRemote() to update values on the Client.

2 Likes

No, I use :OnUpdate with remote events and it works fine.

4 Likes

so if I do that for like 20 values it won’t error?

2 Likes

No, but if you’re worried about bandwidth you can always just limit your own throughput.

3 Likes

I’m a little confused to the use of “Datastore2.Combine”, still.

If I have two scripts in ServerStorage and they both independently use the same datastores, should I call “Datastore2.combine(main, store1, store2, store3, store4)” in both of the scripts? Or do I only need to call this in one of them?

2 Likes

only one of them I think, that’s what I do and it works

2 Likes

@Kampfkarren

so basically calling through remotes for every client is better than using a .Changed event if you are already updating the leaderstats through OnUpdate, to display the latest value in a GUI component?

2 Likes

This has been answered in the thread before, but the only thing you need to care about is that the data store is combined before you use it anywhere.

1 Like

If you already have a leaderstat, then just use Changed. It’s replicated either way.

1 Like

Thank you for the help! Now that I know AfterSave is a thing, I’m going to revert the module back to it’s unmodified state.

Can’t @Crazyman32 's plugin be used with this?

Doesn’t DataStore 2 save data with some sort of scope because of its saving methods?

Image

image

why wouldn’t the name be DataStore2?

It can. If you searched “datastore2 data store editor” you would have found a solution. The data store name is dataStore2.Name .. "/" .. dataStore2.UserId so that means if I join your game and your game has "coins" data then you would do "coins/129574502"

1 Like

@sjr04

what scope would I use?

I couldn’t find any results for editing the data , though I did for how to clear.

Image

image