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

DataStore2

Documentation | News | Source

DataStore2 is an open source module that uses berezaa’s method of saving data that prevents data loss, caches, and verifies data before saving. DataStore2 has been used in my game visited by 120 million players with a constant concurrent player count of around 3,000 - 8,000 players, one time reaching 12,000 concurrent players. @AlreadyPro’s latest game Fairy World has 3 million visits and a consistent concurrent player count above 1,000, and a peak of 5.8k players, and was featured by Roblox. @vCaffy’s Dungeon Quest uses DataStore2, and has at the time of writing 350 million visits and a consistent player count of tens of thousands.

To this day, I have yet to receive a single case of data loss.

If you also use DataStore2 in your production game, let me know! I’d like to know the reach of my work.

Where do I get it?

You can download the latest version of DataStore2 on the releases page on GitHub. Simply download the rbxmx file and drop it into Studio.

How can I stay up to date?

I will be posting news, changelogs, help requests, etc on this thread. Please mark it as “watching” so you get notifications whenever I post on it.

Documentation

The documentation for DataStore2 is available at DataStore2.

From there, you’ll be able to find examples, API reference, etc. This documentation is new, tell me if you like it or if there’s any issues!

Example Code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local DataStore2 = require(ServerScriptService.DataStore2)

-- Always "combine" any key you use! To understand why, read the "Gotchas" page.
DataStore2.Combine("DATA", "coins")

Players.PlayerAdded:Connect(function(player)
	local coinStore = DataStore2("coins", player)

	local function callRemote(value)
		ReplicatedStorage.CoinAmount:FireClient(player, value)
	end

	-- Fire a remote event to the player telling them how many coins they have.
	-- If this is their first time playing the game, they'll start out with 100.
	callRemote(coinStore:Get(100))

	-- Everytime the coin store updates, we'll send the RemoteEvent again.
	coinStore:OnUpdate(callRemote)
end)

-- This is a RemoteEvent where a player can purchase a product by its name.
local Products = require(ReplicatedStorage.Products)

ReplicatedStorage.BuyProduct.OnServerEvent:connect(function(player, productName)
	if not Products[productName] then return end -- Make sure the player is buying a real product

	local coinStore = DataStore2("coins", player)
	local productPrice = Products[productName].price

	if coinStore:Get(100) >= productPrice then
		print("Buying product", productName)
		coinStore:Increment(-productPrice)
	end
end)

Please do not hesitate to ask if you have any concerns or questions.

1445 Likes
Concerns about Berezaa's datastore saving method
DataStore2 News/Changelog
Simple Datastore Handler Tutorial
How to save this data with the PlayerRemoving event
Need help finding how data losses occur with working datastore code
Help with this Non-FE Datastore Script
[OPEN] [1000 R$] Need a scripter that is experienced with Datastores
Saving Stats with DataStore2 (DEPRECATED)
How to save Dictionary using DataStore2?
Best way to handle DataStore data management?
[DataStore2 module] How would I erase every DataStore for a player?
Give me your example of saving data
Kampfkarren - Extremely Experienced Scripter for Hire
Datastore vs datastore 2
Saving a table using DataStore2
Datastore loading half of data?
Global Datastores
More DataStore2 problems
Why is :GetAsync returning table: (value)?
What is the best way to store data?
Making an item save when bought
"attempt to call method 'SetAsync' (a nil value )"
[Closed] Destroyer878878 - Scripting Portfolio
How to save mesh textureId when player leaves game
[HELP] Simulator Scripts not Working Correctly
Creating a battle system: OOP style!
Issues with DataStore
[FEEDBACK] Saving A Player's Progress When They Leave
Data Store grouping question
Help with datastore 2
[FeedBack] on a little something i made
Obby Help! I need to get autosave system
DataStore sometime don't save
Datastore2 issues
Can i save Data in another site?
Game Experiences data Loss!
[OBBY CHECKPOINT] Could this work?
Data Not Saving 2
Revolution Documentation
How to transfer to DataStore2?
Is there a way to check if a player is in game from UserId
Is there a way I can put stats other then leaderstats?
DataStore2 saving table?
Problem at bans in a admin script made by me
Data Saving Issues
Player handling for game using OOP
Sometimes players lose some of their data
(deleted by user)
Datastore data loss
Trouble with loading DataStore?
DataStore2 vs. GetEnveloped's Datastore Handler
DataStore2 doesn't show in toolboxes, and now I can't publish over it
DataStore Improvement
How do I make this script for DataStore2 save
MewsData - A powerful datastore module
Lava Ascension Update 2/15/20
How do I synchronize DataStore 2 data with other plates?
How do i create a saving system for parts using DataStores?
Is it possible to save the children of a folder with DataStore2?
Data handling methods
DataStore Value Problem; Shows Wong Value
How do I utilize DataStore to load/save leaderstats when a player joins/leaves?
How can I save data under a string with datastore2?
Hiring A Scripter To Create Leaderstats That Utilize DataStore2
[OPEN] Hiring Scripter To Create Custom Stats That Utilize DataStore2 To Save Data
104: Cannot store Dictionary in data store
Is there a way to prevent data loss?
Is there a way to prevent data loss?
Is there a way to prevent data loss?
How to make Global Leaderboard using DataStore2?
How to make Global Leaderboard using DataStore2?
What is best way to save this data?
What is best way to save this data?
Object not cloning
Making A New Racing/Car Game
DataStore2 Folder with IntValues?
Weapon save why this is not working
How can i fix my datastore script?
Currency system
Datastore issues: Saves randomly rolling back to a save from 2 servers ago?
DataStore2 Error when saving data "attempt to call a table value"
Datastore not saving (or loading?) data
Trying to create a "bought" door that disappears when a surfaceGUI button is pushed
DataStore problems (Again)
DataSave is not working
Simple Leaderstats not being saved properly
What's the difference between datastore and datastore2?
Any issues with my current dataModule and dataHandler methods?
DataStore sets value to 0?
"Argument 1 missing or nil"
Need help for my entire pet system
How do I make a saving checkpoint system?
Function not giving error but not working as expected
Credits and Attributions
Issues with datastore
My obby datastore sometimes breaks and I don't know why
Is this decent for player data storage?
What values are returned by Datastores for players who have never played before?
Need help for my entire pet system
Worry over losing player data
How to save lots of data without sending too many data store requests?
PostAsync Datastore 2
DataStore not saving when leaving
I want to save tables in Data Store!
How Does Saving A Player's Weapons Work
How would I make a family system?
Roblox Chat Webhooks
DataStore2 Loading improvements
Datastore saving characters?
How should damage and health be handled properly in a game?
Could I get feedback on a data store?
Planning out Data for my players, is this efficient?
Saving Settings in Datastore
Creating a Crate/Spin System
Error in Data Saving!
How do i make skin data save
Data doesnt save
Datastore per player. (It's ok?)
Saving a player's inventory with a specific setup for each item
How to save custom shop purchases
How do you make a auto save part
How to make an autosave every minute
Trying to get used to Promises, what can I improve?
[R$10,000 Bounty] Random Data Loss
When should I save my Datastores?
How Could I Improve A NumberValue Saving System
How do I make this save?
Data value not going up
Making a ModuleScript send back functions
Is there a quick way I can save my games data?
Repeat an event inside the player added
Saving Inventory with DataStore2
Can someone help me to make it saving stats heres is the script and screenshots
Always having issues with Datastore
Datastoring Questions!
Leaderboard names not working
My DataStore doesn't work
DataStore2 Overwriting Table
EZGamepass - Developer Products and Gamepasses made easy and secure respectively :O
Datastore not working
Can I save a folder to a players computer?
DataStores using timestamps?
Pin the "Introduction Thread" post
I want to improve my DataStore code
How to monetize a game and get a least 1k people playing?
Too Many DataStore Requests, How Can I Fix?
Help with Stats
Getting My Saved Randomized Height/Weight With DataStore2
[Update] DataStores Incident: Data Consistency Checker API
How would I perform two datastore requests at once
How do I sync/save a value across all servers in a game?
Editing DataStore2 Data with the Updated DataStore Editor Plugin
DataStore2 request was added to queue warning?
Datastore2 MainModule being destroyed
Is there another way to save game data than leaderstats type of thing
I had to snip this post coz snip
Adding Currency Problem
Scripting Problem
Players data store doesnt save
Players data store doesnt save
DataStore isn't saving Players points
How to avoid flooding DB queries
DataStore2 data loss rate 2-4% of all players
DataStore2 Weapons
DataStore2: Editing Player's Data If They're Offline
Data store doesn't save
[Closed] Grargror - Game Designer, Programmer, Project Manager
Using DataStore2 for multiple saves
Candy/coin pickup system drops fps every time a new candy is made or picked up/collected
What is DataStore2 and why is everyone talking about it?
How to make a tool saving system
Is there a plugin for datastore?
How would I make a race system where it chooses a race for you in rouge lineage
Making chat admin commands using the Chat Service
Using Datastore and OrderedDataStore?
How can I turn this script into DataStore 2?
So You Wanna Script: A Reference Guide for Everyone Else
{UPDATE} Graphical settings for the game named паранойя [Story] or Paranoia [Story]
Saving players datas
Datastore2 Text wont update
Fixing a shop saving problem
Making a off site data store
What Libraries or Tools are used for scripting?
Datastore Problems
Help with Inventory System Concept
Datastores vs Offsite Storage - what's the difference?
DataStore Problem/Data Loss
Starting basic scripting
Datastore broken
Datastore broken
Player Folder Objects Dissappear Before DataStore Saving
Money Script Not Working
Help with datastores
Managing Data Stores for different Saves
Datastore2 Is here and I don't know anything/I am confused
Donut Bakery Life: Chapter 2!
How do I use Data stores?
WE's Robbery Kit (Open Sourced!)
Is it possible to make leader boards using datastores 2?
Why is this script not saving data?
DataStore problem - HTTP 500-Internal error servor
How do I save GUIs between games?
Local script can't get datastore2 module in serverstorage
Fakejeffret Games game Credits
DataStore2 :Set() not working?
Anyone know any improvements for this data saving script?
Sharing dictionaries across all servers in-game: How do I do it?
Datastore2 dictionary saving
How can I keep track of player data better to ensure people don't lose their data?
DataStore not working
How do I make an IntValue save in a DataStore?
Conso's Simulator API [VERSION 1]
Do I really need to do a timed autosave?
Sunsetting Legacy Data Persistence Systems
How should I save my table?
How are DataStore2's keys saved?
How can I create a ban/unban system using DataStore2?
Sword Smith | Script Swords in Just Minutes! [FREE]
Shop data store cash?
How do I make a tool shop system?
Broken data script
[Updated] DataStore2 Creator Plugin/ Folders / Tables
How To Load A Character a Player Has Customized into Another Place?
Saving data through httpservice?
Making a GUI shop
RoPlay - Update Log & Attributions
Table data is not saved with DataStore2 randomly, even though "confirmation" with prints says it is saved every time
How would I do a tempban script?
Why wont my datastores work?
How to save a players data in a new place
Should I not award purchased coins if coin save fails?
Where is the best place to store the stats?
Script says I have no data, even though data was saved
How can i improve this DataSave script?
The Best Way To Save Player Data
Database won't save... [Datastore2 Usage, Please Help]
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Data Store
How to prevent data loss when the servers are down
Making a quest system
Data Stores 2 saving / loading issue
How many datastores allowed per game
Is there an advanced dataStore that does not have data loss?
DataStore Question
Liberty Ville Update Log
Is it inefficient to save 9+ Datastore2s at once?
Help with updateasync()
Problem with Data Stores
Help with updating gamepass multiplier loop
Rare issue where all datastores will wipe
Beginner Data Storing Tutorial
What type of Data Stores that are easy to learn, not complex, and are super fast and reliable should I use?
Should I release the game with roblox data store?
Save data reset. How to stop this from happening?
Dora's Hangout | Credits
Is there a way to detect when a player's datastore changes/updates?
I got 2 complaints saying they lost their data?
Help With Save Data Script
Current Best Practices / Libraries for Data Storage?
For some reason datastore saves only one data
Help, my game is experiencing DATASTORE LOSE
How can I keep my data from saving if pcall fails?
Datastores screwing me over (No error message?)
Datastore2 added to queue issue
PLS PLAY - Update Log & Attributions
[PLS HELP]"DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = "
DataStore2 Optimization Question
Fairy Emotes | Credits
Is it possible to combine Datastores that do the same thing into 1 function?
Saving/Loading, I cant find much about it
MongoStore - An alternative to DataStores
My datasave was erased last night please help [script of my datasave]
How do I check if someone has already joined my game before?
Datastore2 Confusion
When a new player joins a value should one but is zero
Datastore backup
How do I use datastore
SimplyStore | Automatic Datastore System
Can Datastores Handle Shutting Down All Servers?
Checking if data has been added to a table
Save and load multiple data?
Data loss starting two days ago
Storing Player Data - Server Sided
Data Store Issue?
Data Stores Data Loss Issue
What common libraries or tools do you use?
[Open Sourced] Data Deserializer And Instance Serializer
Can you datasave strings?
[HELP!] Can someone plz explain why datastores arent saving most of the time!
Stop using SetAsync() to save player data
Create Place Async Description
Causes of player data loss
What better ways are there to storing user data in a DataStore?
Saving and Loading Inventory
Off-topic posts bump unrelated content: 3 category-sorting proposals
Saved equipment when bought sometimes saves only to 1 server
Data Store Help
Data store doesnt save data
Data store doesnt save data
Creating a battle system: OOP style
How should i handle DataStores failure?
How does the overview core of Studio Work?
Data Store Help
Complely confused on HTTPS saving
Datastore data loss
Inventory in Universes
Best way to make a DataStore?
Tips for creating a data saving system
Help with iterating through tables?
Need a Scripter For Just 3 Scripts [Reward In It As Well]
Storing player data?
Player Data not being loaded in correctly
Having trouble understanding where required module by assetID exists
Placement System Datastore Loading
Saving tools data with DataStore2
HTTP Service with Amazon Lightsail
How would I store an Application on a Datastore
Need Help With A Tycoon Saver
Require Datastore2 blows leaderstats in Studio
Backpack Save Convert to PlayerGui [SetAsync]
Unable to upload to certain models using the new configure asset window
HTTP 405 (Method Not Allowed)
What do you guys think the best way of transferring to DataStore 2 is?
Are there any other databases apart from Google Spreadsheet (Help)?
Question about transferring game objects in teleport?
How does my Auto Saving script look like? Will it ever error?
How to Gather Player Data
Can Datas Only In Leaderstats Be Saved?
How can I add more values into DataStore without overwriting data
Trying to implement saving into Zblock's Placement System but I cant seem to do it
Output says Datastore queue is being filled?
Datastore inefficiency problem
How wait for players data to load in seperate script (problem in multiplayer studio tests)
How to use datastore with tables in server?
Need help with DataStore2
How to save a value in a server?
What would be the best way to save/load data reliably?
Datastore vs datastore 2
How do I even handle DataStores
My DataStore randomly fails why? (New Developer)
MewsData - A powerful datastore module

Awesome tutorial. Datastore2 is unequivocally going to help some people, myself included. I’ll definitely try it out myself in some upcoming projects of mine. I also find fascinating that an idea from @berezaa is started to develop into further ideas from other people and thus, I can’t wait to see what other good ideas that come from it and this module. :smiley:

116 Likes

For our new members out there, this is the method berezaa uses:

137 Likes

I updated DataStore2 with a minor typo fix (you’d have to make a value named SaveOnStudio instead of SaveInStudio). This reminds me to inform you that if you’re not using the require ID method to please “Watch” my repository to know when the module updates.

49 Likes

Actually made me tear up a bit. Glad to have been able to help :blush:

155 Likes

Added a “Gotchas” section for common mistakes you may come across when using DataStore2.

49 Likes

This. :revolving_hearts:
Is. :two_hearts:
Beautiful. :sparkling_heart:

EDIT: In the future, making this so that you don’t have to have a player instance, but just a datastore key would also be incredibly helpful!

47 Likes

The problem with just a data store key is that DataStore2 only saves on leave, so it’s not guaranteed the data you’re trying to get will be the same. What’s the use case for non-player instances? I can add it if I feel the use case is valid.

41 Likes

I’m definitely aware that there aren’t as many uses for a regular dafastore key, however, some games may use a global weather systems, notifications, etc. However, with DataStore2, would these systems really require this complexity… :thinking:

Either way, amazing system. Just integrated it into my game and the speed is definitely noticeable!

33 Likes

I think for the use cases you provided the benefits of DataStore2 would not be applicable or noticable, you’re much better suited using standard data stores or HttpService.

Glad to hear DataStore2 is working for you, can you message me a link to your game so I can use it as a success story? :slight_smile:

30 Likes

:AfterSave was added a little bit ago. In order to fix a minor memory leak, I am going to inform all users to remember the rule of not using DataStore2 in PlayerRemoving. This will now be enforced when this memory leak is fixed. Move everything you might put in PlayerRemoving for DataStore2 in AfterSave callbacks.

29 Likes

Suggested by yours truly

34 Likes

Added a backups section and three new APIs for backups in the case of Roblox outages.

27 Likes

That would help me too, I haven’t really used a Datastore 2 before :wink:

33 Likes

I can look into it @Aorda @Beartikal.

28 Likes

An issue with BeforeInitialGet has been spotted to where it is called on every :Get(), rather than just the first time. If you are currently using BeforeInitialGet, be prepared for this to change.

22 Likes

Added :GetTable, a method that makes it much easier to add new keys to tables in your data store.

20 Likes

Video with information on how to use it and do more complex saving like whole inventory tables, not just one coin number would be awesome :smiley:

32 Likes

I’m not a fan of video tutorials and I’m not under the right conditions to record a video at this point in time, sorry :frowning:

23 Likes

Been trying to set this up, but I feel like a lot of the documentation is really vague. The biggest issue is I have no idea how to obtain previously saved data. Does the Get() function grab a key? A value of something? Really confusing.

For me personally, having the functions written like this is also extremely frustrating:

Variant DataStore2:Get(defaultValue=nil, dontAttemptGet=false)

It’s really hard to understand what the parameters mean. The “variant” and “=nil” stuff makes it difficult for me to figure out the arguments I should use. I get you’re trying to be informative but can you make it slightly more readable?

And the descriptions aren’t that helpful. Is defaultValue supposed to be the key of the thing I want?

Also your example code isn’t helpful that much. Why are you using the comments to explain stuff totally unrelated to the module (e.g. “–Make sure the player is buying a real product”)? I’m confused on what exactly you’re giving the player when they join too… Are you getting them a value 100 or setting them or what? Very hard to understand.

I really would like to use a stable saving system like this but it’s confusing to set up. I hope you can address that stuff.

29 Likes