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

Does that work when the player isn’t in game?

I dont tested it yet when the player inst in game, but I will look at it.

I’m interested in using DataStore2 for multiple upcoming projects, but it appears to be missing an important feature that I would need in order to implement it into my game.

Does DS2 allow for DataStores that are not tied to any particular player? For instance, one feature I want to make in my game is a “Clan” feature in which multiple people can be in the same clan with separate data. I do not see a way to implement this without tying the clan data to a particular player, which would prevent me from being able to get the data if the player is not in the game.

I may have overlooked this in the docs, as it seems like a basic feature to include, so I figured I would ask here.

1 Like

It does not. You’ll have to use regular DataStores for your clans feature, but you could still use DataStore2 for player’s data.

1 Like

Can this work with Color3Value, is it compatible ? I want to know.

I have a scripting support topic open regarding a bug I’m encountering with DataStore2, I’m going to go ahead and link that here in hopes that someone who is familiar with all of this can help me out.

You can’t save Color3s directly in data stores, so you can’t save it in DataStore2. You can easily serialize it, however.

Okay what about BrickColorValue or should i just convert in NumberValue?

you can only save numbers, strings, or booleans.

so if you wanted to save a BrickColor, you would simply save a string like “Bright Red

you can even use strings to save an RGB value. “255, 255, 255”
just parse through the commas to get each number by using string.gmatch() and tonumber()

I wish I knew enough about using github to do this submodule thing. I use Rojo and VSC for a lot of reasons but not really because of GitHub.

I do wish there was a way to just use the module in VSC without having to do all of that. Is there any particular reasons you decided to start adding scripts as children of other scripts? This design makes it difficult or maybe even impossible to have the Datastore2 module on a PC. I always felt that sort of code organization was bad practice but I realize it is just my opinion.

How do you use the DataStore Editor made by Crazyman32 with it?

The keys seem to be saved as ID/DataStoreName, or ID/MasterKey, can’t remember. So if you have a data store for "coins", you can do 129574502/coins to get my coins for example

1 Like

It dont work when player inst on game. (I would like very much if someone teaches me how to set a player’s data using their ID.)

I showed how in this reply. You just need to create a fake player object.

I tried it too, dont work. I got this error:

20:56:18.147 - ReplicatedStorage.Modules.DataStore2:479: DataStore2() API call expected {string dataStoreName, Instance player}, got {string, table}

I forgot about how DataStore2 started checking for value types. You can fix this by deleting lines 483-490 in the DataStore2 module. Here’s what those lines look like.

assert(
		typeof(dataStoreName) == "string" and typeof(player) == "Instance",
		("DataStore2() API call expected {string dataStoreName, Instance player}, got {%s, %s}")
		:format(
			typeof(dataStoreName),
			typeof(player)
		)
	)

Nothing happens when the value change, I deleted those lines tho. My code:

	local player = {
          UserId = 249598128,
          AncestryChanged = Instance.new("BindableEvent").Event
    }
		local BanStore = DataStore2("banned", player)
		BanStore:Set("banned")
		BanStore:Save()

I figured it out. Its MasterKey/UserId. Then the actual key is a number value that reflects the amount of time the player has joined the server or something weird.

1 Like

I’ve been using DataStore2 for a while and it works great. However I’m running into issues when games shutdown for maintenance. I tried binding to close to make sure everything saves properly. My players end up getting older saves however.

To add on, you can save tables and dictionaries as well.