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

Did you figure out a solution? One that I had is to put Datastore2 in the Aero Modules folder, then simple create a new Aero service and within there, create a method for each of the Datastore2 methods you are using. Simple require the module as you normally would without using Aero.

You could also use this service to load and combine player data. Since Datastore2 still doesnt combine keys automatically, you will need a service to do that anyway.

Theres a way to set a player’s data using his user id?

No need, data is already saved when player leaves. Also, there is DataStore2:Set(value) to set data. I also believe there is DataStore2:Save() but it shouldn’t be used often but I haven’t used datastore2 in a while so I’ll check it out soon.

I need it because I’m making a admin system, and I want set a player with a user id banned for example.

Something like this will work I think.

local fakePlayer = {
    UserId = 1,
    AncestryChanged = Instance.new("BindableEvent").Event
}

local ds = DataStore2("coins", fakePlayer)
ds:Set(100)
ds:Save()

Haven’t tested, but something close to this should work.

I just noticed that I could use Players:GetPlayerFromUserID and it works lol, thanks too.

1 Like

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.