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

That module is long gone since 10 months, and the topic has been locked as well, there is absolutely no reason for you to use that module.

Using this or profile service should be decided by your self, based on your needs. ProfileService offers a powerful API and has session locking with one of it’s primary features, whereas DataStore2 offers a somewhat bloated API (but a lot comprehensible) and has backups as it’s main feature. With that being said, I highly recommend using ProfileService.

1 Like

yes i agree in some parts

agrees
the module is long gone ( there was no update and this thread seems to dead )

datastore2 is bloated ( very agreeable )
disagrees
datastore2 backups ( its totally useless now since versioning exists )

conclusion

i will try out profile service it seems pretty popular currently

and thanks for tanking your time to answer this question

Here’s an updated version where you can call it using instances or player’s userid:

@Kampfkarren
Thank you for sharing us this wonderful module. Here’s changes I’ve added:

  • Detects 2nd parameter if it’s Instances or Player’s UserId
  • If 2nd parameter is Instance, set Instance to Instance’s UserId
  • Checks if Player’s Instances of Player’s UserId exists
  • Checks if Player’s Instances exists and if so, then create an AncestryChanged event.

And then modified your quick hacks:

Works wonder, it prints all the datas of other players even without being in-game. Useful for these:

  • ROBLOX’s Right to Erasure - Action Requested
  • Admin Abuse Data Reset (When an admin in your game abused his powers, you can easily revert back the data)
  • Resets Player’s Data

How to try:

DataStore2(dataName,UserId)

DataStore2:Get(nil)

I printed somebody’s whole data and I can assure you it’s not mine:
image

File:
UpdatedDataStore2.rbxm (18.2 KB)

1 Like

Wait, why should we use your changes rather than the vanilla Datastore2? You never clarified on why I should use yours, and is it backwards compatible with vanilla Datastore2?

Is it possible to create a data store with this module that does not belong to one specific player? As in, a way to make a data store that all the players can access? Should I just use a regular datastore for this?

Another question adding on to this:
If I need to use a regular datastore, does this module work interchangeably so I can use DataStore2 for some data and the regular Roblox datastore for others?

You should use regular data stores with this, you can just use both at the same time.

Hey there! A few questions I would like to ask. I am fairly new with this module and from what I have picked up so far is basically that data gets saved or put on an in game cache which are the keys. The combine basically then takes all the in game cached data and puts into a big table which then gets saved? My first question is, why would you then save a table in the first place if combine does that for you. That just creates more pain as then you have to get the table, and insert your new values compared to just being able to directly update 1 value which later gets put into a table.

Will you implement a function for session locking like profileservice?

Is it ok to save lots of data under keys and not use tables at all?

Would datastore2 be a good module to create a player guild system with?

And finally, using both datastore2 and profileservice wouldn’t work right?

If you answer these questions that would be great man! I am developing an rpg game with lots of systems e.g inventory, character customization, guilds ect. Have a great day and if you reply thx so much!!

No, I never needed it, and nobody has sent a pull request yet.

Yeah, but why are you afraid of tables?

You can only access data from players in game. So probably not.

It’d work fine if you use standard data saving.

Well, I am new to datastores and I have been slaving over for days now trying to save tables and update values in it. Also, I have been scripting on and off for 2 years now and I gotta say the biggest hurdle is not learning how to script, its learning how to script efficiently and have optimized code. I never really took that into consideration so now its like I am screwed. Anyways, thx man for answering

I’m making a slot system, is this an effective way?:

local sss = game:GetService("ServerScriptService")
local DataStore2 = require(sss.MainModule)
local slot = --slotnumber

DataStore2.Combine(
	"DATA", 
	"value1".."Slot"..slot, 
	"value2".."Slot"..slot, 
	"value3".."Slot"..slot, 
)

game.Players.PlayerAdded:connect(function(plr)
	local value1Store = DataStore2("value1".."Slot"..slot, plr)
	local value2Store = DataStore2("value2".."Slot"..slot, plr)
	local value3Store = DataStore2("value3".."Slot"..slot, plr)

    print(value1Store:Get(5))
end)

umm… where is wrong inn my code…i dont think its wrong…can someone tell me where is wrong in my code?..
attempt to index number with ‘Own’

Looks fine, as long as you ensure everything is combined properly.

This isn’t the code that’s erroring, as “Own” is nowhere to be seen.

Hi. First of all thank you for the tutorial :smiley:

I have an optimization question.

How heavy is store:Set(value) on performance? I have a custom inventory system, and there are cases where there might be done store:Set() every second for each player, to update their inventory. Here is the relevant chunk of code

if hit.Name == "GoldMine" and state.Value == "Attacking" then
		
		inventTable["Golddust"] += 1
		inventStore:Set(inventTable)

	end

Will this affect performance too much? And if so, how can i improve this?

Extremely cheap. It doesn’t do any saving on its own.

1 Like

Flummoxed by this error:

Suggesting the value is not a table. The code in question:

local defaultKillCount = {
	Rat = 0,
	Crow = 0,
	Slime = 0
}
local killsStore = DataStore2("Kills", player)
dataKillCount[player] = killsStore:GetTable(defaultKillCount)

That’s it. I ran it once for one player and it worked first time only. I did not update the table from the default values (just checking the code), and now it is completely broken. Is there a workaround to salvage this datastore?

EDIT: must have been a save error in the initial setup. I saved the default table over it manually and now everything works again. I’ll get my save functions up and running!

EDIT2: nope, still broken!

EDIT3: OK, it appears during one of my early tests, I accidentally crossed datastores, filling Kills with “Experience” from Stats. I can no longer overwrite the contents of this datastore. It acts like it overwrites, but then it goes back to this value. The error is because a string is not a table (predictably). Unsure how to clear this datastore out and try again.

1 Like

I love this module, but I’d like to know: How does it manage to not hit the datastore limits??

I’m making a ban system with this datastore and was wondering, is it possible to edit a player’s data that is NOT in the game. I need a way to unban a player (reset ban value to original, which is unbanned) and I don’t know how to do this without them being in the game.

:Save() (or these days, SaveAll) is never necessary. DataStore2 auto saves when the player leaves.

No.

https://kampfkarren.github.io/Roblox/guide/gotchas/

The normal way of doing data stores is to keep a cache somewhere of a player’s data (such as in a folder or using leaderstats), then saving when the player leaves. It is wrong, however, to use DataStore2 this way. DataStore2 is built to be used whenever your data actually changes. You shouldn’t invoke DataStore2 in PlayerRemoving at all. Don’t worry, :Set will never error or do API calls, it’s all cached. DataStore2 will save the player’s data before they leave.

2 Likes

There is no native way with DataStore2 for a plethora of reasons. You can do it manually.

1 Like