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

Wow my mistake, i thought i read that in the OP

EDIT: It was this

  1. DataStore2 does not save in studio unless explicitly told to.

This was added because with multiple usages of DataStore2 (i.e. for several different keys), the game would take way too long to finish up because of all the BindToCloses. Thus, DataStore2 will not save in studio unless it is told to. For DataStore2 to save in Studio, you must create a BoolValue named “SaveInStudio”, and check it to true. There will be a warning when using DataStore2 if you do not have this object, and a separate warning (to save you from yourself) to tell you when a data store isn’t saved because the option is off.

So we have to modify the module to get it to save in Studio? Where do we create this BoolValue?

2 Likes

No.

ServerStorage, the warning should say that.

6 Likes

I’d really appreciate some help i watched @Alvin_Blox tutorial and tried to to apply it to a table. This is the code i got. The thing is this doesn’t seem to save the updated value like it did in the tutorial video. I’m probably missing something obvious. The code is supposed to check if the player is in the database and if so get the stored table. If the player isn’t then it will set it to defaultvalue.

local DataStore2 = require(1936396537)

local defaultvalue = {}

local OwnedCars

game.Players.PlayerAdded:Connect(function(plr)
	
	local carDataStore = DataStore2("OwnedCars", plr)
	
	
	
	local function carsUpdate(updatedValue) -- updatedValue = default value OR passed in by OnUpdate
		
		OwnedCars = carDataStore:Get(updatedValue)
		
	end
	
	carsUpdate(defaultvalue)
	
	
	
	carDataStore:OnUpdate(carsUpdate())
	
end)
1 Like

You’re calling the function by mistake. Replace this with carDataStore:OnUpdate(carsUpdate).

Now it will only pass my if typeof(carDataStore:Get()) == "table" then check before it’s updated. Any idea why? I set it by doing table.insert with the table i got from Get() and adding the value and then i do Set() with that.

It’s not a DataStore2 issue, it has to be your code.

Alright. Thank you Karren :slight_smile:

1 Like

Really helpful,
Before this, when I wanted to store tables, I had to save data in a string.
DataStore2 is really easier than this. great job. :clap: :grinning:

1 Like

No you didn’t? DataStore2 doesn’t do anything special with tables, they’ve always been savable in data stores.

1 Like

Well, they weren’t!
It causes error.
or I’m wrong?

1 Like

Yes, you’re wrong–only some tables cannot be saved (mixed tables and tables with data that couldn’t be saved anyway like Instances). DataStore2 doesn’t do anything special to tables.

1 Like

Really?.. but my table doesn’t include these :confused:

1 Like

If it didn’t, then it wouldn’t error.

1 Like

Maybe there’s something wrong with my place…

1 Like

Is there any plugin like Crazyman32’s Datastore Editor for DataStore2?

2 Likes

No, but it’s on my to-do list, no ETA.

6 Likes

I feel as though you are blacklisted from Studios Toolbox because I can search by author, grab your model, and even search its name but you absolutely do not come up anywhere.

1 Like

I’ve been looking into this–others have reported it as well and it’s happened to me a few months ago. I’m hesitant to say it’s a blacklist, the module still works and I’ve gotten zero message on it.

Temporarily, you can use:

game.InsertService:LoadAsset(IDHERE).Parent = workspace

…in the command bar and find the module inside a new model in the workspace.

3 Likes

Will datastores save a instance or the value of the instance. Is it also possible to store string, number and bool values in the same datastore
Which one will a datastore save:

local bool = boolValue.Value

Or

local bool = boolValue

2 Likes

DataStore2 doesn’t have different regulations from different data stores, so instances don’t save. You can use BeforeInitialGet/BeforeSave to serialize and deserialize them, but it’s easier to just save the value.

3 Likes