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

#184

Are you going to switch from os.time() to incremental version numbers soon?

2 Likes
#185

Yes.

3 Likes
#186

Incremental key saving has been pushed to the prod script. Tell me if you have any issues.

1 Like
#187

For anyone dealing with GDPR, I believe this script I whipped up will work. Put this in your command bar then use clear(userId, name) (also in the command bar) to clear someone’s data.

If you use combined data stores, the name will be your master key. Otherwise, it’s your normal name.

local DataStoreService = game:GetService("DataStoreService")

function clear(userId, name)
	local orderedDataStore = DataStoreService:GetOrderedDataStore(name .. "/" .. userId)
	local dataStore = DataStoreService:GetDataStore(name .. "/" .. userId)

	while true do
		local pages = orderedDataStore:GetSortedAsync(false, 100)
		local data = pages:GetCurrentPage()
		for _, pair in pairs(data) do
			print(("key: %d"):format(pair.key))
			dataStore:RemoveAsync(pair.key)
			orderedDataStore:RemoveAsync(pair.key)
		end
		if pages.IsFinished then
			print(("finished (%d: %s)"):format(userId, name))
			return
		end
	end
end
14 Likes
#188

Adding different save slots might be a cool feature.

#189

Uploaded v1.0.2:

This fixes an issue with :Save() overriding itself when called more than once on the same store. As always, it’s published on the model and tell me if this breaks anything.

#190

Is there a way to edit a player’s data through studio?

Like in the event I forget to shutdown a game for maintenance, and they happen to join while I’m editing something that requires Data stores & they run into it before it was planned for release.

#191

You can by making a mock player to pass into DataStore2 and using the command line (i.e. a table with a UserId, and shims for whatever else DataStore2 uses like PlayerRemoving).

2 Likes
#192

If anyone has :SetBackup(3) examples to show, I’ll appreciate! :slightly_smiling_face:

2 Likes
#193

Is there a way to transfer data from roblox’s datastore to datastore2?

#194

No, but you can have your code check if the player has no data in DataStore2 to make a check to the original data store. If there’s data in the original store, transfer it over to DataStore2.

1 Like
#195

Can you provide an example for this? I know that Crazyman’s datastore plugin can edit specific datastores but I don’t think it’s compatible with this.

#196

It works with this, it’s just a bit tedious.

As for what I mentioned, I believe you can do something like:

DataStore2("storeName", { UserId = userId, PlayerRemoving = Instance.new("BindableEvent").Event }), use that, then call :Save() on it. DataStore2 doesn’t check if it’s a real player.

2 Likes
#197

We have started using your datastore module for Balloon Simulator (https://www.roblox.com/games/2756231960/CODE-ROBO-Balloon-Simulator)

We have not any reports for data lost issues! The game detects if you are in the old datastore and then transfers your data to Datastore2.

Good job on making that module :slight_smile:

4 Likes
#198

Hey, I have been messing around with this for a bit now. I noticed when I setup a callback function for :OnUpdate() under as CombinedDataStore

It calls the callback function twice. So I did some digging and I noticed that when I call :Set() it triggers the callback function twice.

Should the _dontCallOnUpdate be true for when :Set() is called (snippet down below)? Since, self:_Update() being called twice anyways.

function CombinedDataStore:Set(value)
	local tableResult = self.combinedStore:GetTable({})
	tableResult[self.combinedName] = value
	self.combinedStore:Set(tableResult, true)
	self:_Update()
end

Right now, nothing being pass for _dontCallOnUpdate

Other than that minor issue, great module so far! :+1:

1 Like
#199

Isn’t this abusable by exploiters to make infinite money?

#200

No? The example is in a server script and the server will still have authority.

#201

I’ll fix it, thanks for the find.

#202

Are you sure the issue is not that :OnUpdate is called when any data store of a combined data store is called? That’s what I’m observing right now.

Can you try this version of the code and tell me if the issue comes up?

#203

Maybe? I just tried that version and I am unable to get the issue anymore.