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

No, there is not.

1 Like

Is there a temporary fix for this? Would turning SaveInStudio off work? Couldn’t find where to put the SaveInStudio boolean value, so that’s why I’m asking. Would be really good if there was any temporary fix, because waiting 2 hours a day for playtests to stop is extremely inefficient.
(I have read that it is not your fault)

I added this to my DataStore2 file for now.

7 Likes

Is there any status update on getting user data without a player? You’ve answered it many times that it’s planned, but I must say – I desperately need this feature for my game to properly leverage DataStore2.

Without this feature I’m afraid my title will be unable to adequately leverage the benefits offered by DataStore2, and I will need to continue using stock data stores.

These two methods cannot be upgraded to DataStore2:
-- Serializes an object-representation of save data that has been edited within studio and applies it to the specified player. Primarily used to grant players special items or perks.
function DataPersistence:WriteDataFromObject(userId, object)
	local data = Objectifier:Deobjectify(object)
	local json = HttpService:JSONEncode(data)
	CharacterStore:SetAsync("Data_U-" .. tostring(userId), json)
end

-- Deserializes save data into an object representation that can be edited within studio.
function DataPersistence:PlayerDataToObject(userId)
	local loadedData = HttpService:JSONDecode(CharacterStore:GetAsync("Data_U-" .. tostring(userId)) or "[]")
	local object = Objectifier:Objectify(loadedData)
	return object
end

These three methods are very important and removing them / temporarily decommissioning them is not an option at this time. The reason these are so important, since the use case may seem quite odd, is so that I can easily debug or alter my playtesters’ data without needing to specially write scripts to execute during runtime when they join the game.

Not much progress has been made on it, though it should be easy enough for you to go in and add–there’s probably only a few sites where it being a player matters (like with PlayerRemoving).

1 Like

I have yet another issue

When I call :Set() the cache is updated, but when I leave the game (this is occurs in game as well as Studio), it does not save/update the Datastore.

e.g. I have 2 pets. when I try to buy more, the ones I just bought are not saved in the petStore table.

Here’s the code I use:

		local petStore = DataStore2('pets2',player)
		local cpets = petStore:Get({Empty = true})
		cpets[#cpets+1] = {true,productName}
		petStore:Set(cpets)
		for i, v in pairs(petStore:Get()) do --this is for testing purposes
			print(v[2])
		end
		ReplicatedStorage.Events.LoadPet:FireClient(player,productName)

Essentially, it grabs the pets table, adds a new value, and uses Set to update the cache. Set is working fine (that’s what the for loop does), but the new cache isn’t updated when I leave.

Is there any way I could fix this? (i.e a different function or saving method)

Hey I came back to read about older posts and now I see this I am getting doubts whether I used orderedDataStores right together with datastore2 (without setting the saving method to standard since its vital to not mess with the current data)

Did you mean with this that the orderedDataStore also has to get combined with .combine()? or only the datastores which are assigned to players (such as “coins” or “inventory”)?

Only DataStore2 stuff needs to be combined.

Unfortunately, with this little information, I can’t understand your problem other than to tell you it’s 99% likely that it is not a DataStore2 bug.

3 Likes

If you get the error “Not running script because past shutdown deadline”, it’s not DataStore2’s fault.

This error occurs because roblox studio has a bug that whenever you have yielding code inside the bindtoclose() function, the game will “crash” resulting in the error I just mentioned.
because of this, your data is not being saved while testing in studio.

This is currently getting fixed by roblox staff but it can take a while.

1 Like

Important Edit: I had to switch the value from a string to an integer to save a table. Not sure why, but it’s fixed.

My issue was that it wasn’t updating one specific datastore, that being the one which saved values in a table.

It wasn’t throwing errors, and I added the :BindToClose() patch earlier, but as far as I can tell that didn’t break anything because it was only the pets that didn’t save properly.

The only difference between the pets and the other datastores is that the pets use a table, not an integer. The ones using integers saved their data perfectly fine.

I’ve also tried different saving methods or just straight-up clearing the cache. None of this seems to have worked. Also, if I haven’t included enough information you need to tell me what you need next time.

Will the roblox Datastore2 asset still be updated?

A Roblox bug is preventing me from doing so, so probably not.

2 Likes

Hi,

I am getting this error and can you explain what is this and what causing this?

Happens whenever I play solo on studio


21:49:20.848 - HTTP 403 (Forbidden)
  21:49:20.848 - 502: API Services rejected request with error. HTTP 403 (Forbidden)
21:49:20.849 - Stack Begin
21:49:20.849 - Script 'ServerScriptService.Modules.DataStore2.SavingMethods.OrderedBackups', Line 28 - upvalue callback
21:49:20.849 - Script 'ServerScriptService.Modules.DataStore2.Promise', Line 218
21:49:20.850 - Stack End

I updated the script to the current one and im getting this error now

22:01:26.978 - HTTP 403 (Forbidden)
22:01:26.986 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Data Store = Data_V1/20737205
  22:01:26.987 - ServerScriptService.Modules.DataStore2:80: 502: API Services rejected request with error. HTTP 403 (Forbidden)
22:01:26.987 - Stack Begin
22:01:26.988 - Script 'ServerScriptService.Modules.DataStore2', Line 80
22:01:26.988 - Stack End
22:01:27.639 - HTTP 403 (Forbidden)
22:01:27.639 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Data Store = Data_V1/20737205
  22:01:27.640 - ServerScriptService.Modules.DataStore2:80: 502: API Services rejected request with error. HTTP 403 (Forbidden)
22:01:27.640 - Stack Begin
22:01:27.641 - Script 'ServerScriptService.Modules.DataStore2', Line 80
22:01:27.641 - Stack End
3 Likes

How many datastores did you make man?

1 Like

Only one?

I am storing a table into the datastore2 key just like you would do with the normal datastore

Note: Whenever I test it in the actual game, everything works perfectly.

1 Like

Oh. I thought you were using like 573. It’s probably just a datastore glitch. Just try editing the code or making separate tables. Here’s a list about all the errors a datastore can show. (Or maybe you are loading data too quickly. I dunno, I don’t understand datastores.)

1 Like

Why it does not show my leaderstats

You don’t have API access enabled or you are not a developer in the team create.

1 Like

I have api access enabled and I work alone but still not showing my leaderstats and saving does not work.

I have multiple scripts in my game.
Is it ok if I do something like this?

-- script 1
DataStore2.Combine("MasterKey", "coins")
-- script 2
DataStore2.Combine("MasterKey", "lives")
-- script 3
DataStore2.Combine("MasterKey", "level")

Would all these be saved under MasterKey or would it overwrite the previous?