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.

1649 Likes
Concerns about Berezaa's datastore saving method
Simple Datastore Handler Tutorial
How to save this data with the PlayerRemoving event
Help with this Non-FE Datastore Script
[OPEN] [1000 R$] Need a scripter that is experienced with Datastores
How to save Dictionary using DataStore2?
Best way to handle DataStore data management?
Give me your example of saving data
Saving a table using DataStore2
Making an item save when bought
Global Datastores
Datastore vs datastore 2
DataStore2 saving table?
Datastore loading half of data?
Obby Help! I need to get autosave system
DataStore2 vs. GetEnveloped's Datastore Handler
Datastore2 issues
Trouble with loading DataStore?
Why is :GetAsync returning table: (value)?
"attempt to call method 'SetAsync' (a nil value )"
What is the best way to store data?
Is there a way I can put stats other then leaderstats?
Issues with DataStore
Revolution Documentation
DataStore Improvement
[Closed] Destroyer878878 - Scripting Portfolio
Problem at bans in a admin script made by me
How to transfer to DataStore2?
[FeedBack] on a little something i made
Player handling for game using OOP
Is this decent for player data storage?
Creating a battle system: OOP style!
How to save mesh textureId when player leaves game
Is there another way to save game data than leaderstats type of thing
Data Store grouping question
[OBBY CHECKPOINT] Could this work?
How to use datastore with tables in server?
Game Experiences data Loss!
Help with datastore 2
[HELP] Simulator Scripts not Working Correctly
Is there a way to check if a player is in game from UserId
How do I synchronize DataStore 2 data with other plates?
Data Saving Issues
DataStore sometime don't save
Datastore data loss
How do I make this script for DataStore2 save
Can i save Data in another site?
DataStore2 data loss rate 2-4% of all players
Sometimes players lose some of their data
[FEEDBACK] Saving A Player's Progress When They Leave
Data Not Saving 2
Data handling methods
DataStore Value Problem; Shows Wong Value
Datastores vs Datastore2
How can I save data under a string with datastore2?
Hiring A Scripter To Create Leaderstats That Utilize DataStore2
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
DataStore2 Folder with IntValues?
Making A New Racing/Car Game
Save Data From Universal Games
Weapon save why this is not working
How can i fix my datastore script?
Currency system
What are you working on currently? (2023)
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
My obby datastore sometimes breaks and I don't know why
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
How to make Data Store script more secure?
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
Datastore not working
DataStores using timestamps?
Pin the "Introduction Thread" post
Data Store Error
Too Many DataStore Requests, How Can I Fix?
Help with Stats
[Update] DataStores Incident: Data Consistency Checker API
How would I perform two datastore requests at once
Editing DataStore2 Data with the Updated DataStore Editor Plugin
DataStore2 request was added to queue warning?
Datastore2 MainModule being destroyed
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 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
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
Saving players datas
Datastore2 Text wont update
Fixing a shop saving problem
Making a off site data store
Datastore Problems
Help with Inventory System Concept
Datastores vs Offsite Storage - what's the difference?
DataStore Problem/Data Loss
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
Saving/loading chunks in a chunk-based game
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
Why is my data not always 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?
Data saving does not work
Conso's Simulator API [VERSION 1]
Do I really need to do a timed autosave?
How can I get started with data saving
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?
Dev Product Help
Broken data script
[Updated] DataStore2 Creator Plugin/ Folders / Tables
How To Load A Character a Player Has Customized into Another Place?
TooManyRequests
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
I'm so fed up with data loss, please help!
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
Doesn’t save data when you log into the game again
Is there an advanced dataStore that does not have data loss?
Is profile service better than normal data store?
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
SimplyStore | Automatic Datastore System
What type of Data Stores that are easy to learn, not complex, and are super fast and reliable should I use?
What's the best way to handle a bunch of datastore requests?
Should I release the game with roblox data store?
Save data reset. How to stop this from happening?
Dora's Hangout | Credits
DataStore2 problem: Attempt to perform arithmetic (add) on table and number
Is there a way to detect when a player's datastore changes/updates?
Help With Save Data Script
Current Best Practices / Libraries for Data Storage?
For some reason datastore saves only one data
Player Experiencing Data Loss in my TD Game
Module - Datastore problems
Help, my game is experiencing DATASTORE LOSE
Module Data Difficulties
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
Script with BindToClose callback was destroyed. datastore2 error
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 not saving?
Datastore2 Confusion
When a new player joins a value should one but is zero
Datastore backup
How do I use datastore
Button Simulator Style Game
Can you guys write simple code using datastores?
Datastore2 fetching old backups after successful save
Doom Towers: Credits & Attributions
Advice and tips on saving a table
{UPDATE} Graphical settings for the game named паранойя [Story] or Paranoia [Story]
Is it possible to save data for a game without linking it to a player?
Datasave not working although no warnings or errors in the output
This doesnt work for some reason
[OPEN] Hiring Scripter To Create Custom Stats That Utilize DataStore2 To Save Data
Data Rollback / Reverted
Datastore2 converting string to table
Issue with DataStore for a Shop / Loadout
How to save player stuff
Data Store, Saving Folders and Values
How to save a TextBox's Text
Fazbear Roleplay - Credits
Module script help
Points don't save after rejoining the game(Fixed)
Should I switch datastores?
WalkSpeed Saving Problem!
Pondering DataStores - Why DataStore2?
How would I Prevent Data Loss when Player Leaves using DataStoreService?
How would I Prevent Data Loss when Player Leaves using DataStoreService?
My datastore isn't working (again)
Getting My Saved Randomized Height/Weight With DataStore2
Datastore 2 dataloss
How to make a saved global variable?
How would I make a Datastore2 leaderboard?
How Would I Make a Ending Game's Saving System
Datastore doesn't work
Datastore sends errors DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests
Saving folders content with Datastore2
Help with datastore error?
Leaderstats script not working
Help needed with Datastore 2
What is DataStore? Also how to implement it in my games?
How can I switch from DataStore to DataStore2 without losing data?
Need help with datastores
Error with checking if a datastore key exists
Problem with saving Data
How to improve inventory system?
I'm now trying to make the attribute system in my game save. but I don't know how should I do it
How can I check how much robux a person spent on a in game purchase ( clothes, accessories etc )
Datastore2 not saving character store
Creating a Crate/Spin System
Can Datastores Handle Shutting Down All Servers?
Leaderstats DataSave
My datastore is not working
Candy/coin pickup system drops fps every time a new candy is made or picked up/collected
Server Leaderboard work but global doesn't work
Which datastore should i use?
Subscription Service: Ingame Subscriptions Made Easy
How do I sync/save a value across all servers in a game?
Datastore NOT working
How to monetize a game and get a least 1k people playing?
Outdated Datastore Script?
Error in Data Saving!
My datastore is giving players random stats, and there is lots of data loss
Best way to preserve data
How do I utilize DataStore to load/save leaderstats when a player joins/leaves?
Datastores randomly failing to save data, and I don't know why
Issues with datastore
How to datastore2 more than 1 variable?
Datastore wiping if I leave and rejoin too quickly
Lava Ascension Update 2/15/20
How to let players save OC's with a custom character?
What would be the best way to save/load data reliably?
Saving Stats with DataStore2 (DEPRECATED)
Data getting rolled back?
[DataStore2 module] How would I erase every DataStore for a player?
Need help finding how data losses occur with working datastore code
Change Leaderstats to 2 instead of 1?
# | best posts - free/paid | #
Table stored in DataStore2 not updating
[Vietnamese] Essential Guide to Services on Roblox Studio
Trying to save a LOT of data!
Easy to Use player stat module
Checking if data has been added to a table
EasyDataStores Module
Save and load multiple data?
Data loss starting two days ago
Storing Player Data - Server Sided
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
How should i handle DataStores failure?
How does the overview core of Studio Work?
Data Store Help
Datastore data loss
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)
Need help with DataStore2
How to save a value in a server?
Minute Counter Bug!
Datastore vs datastore 2
How do I even handle DataStores
My DataStore randomly fails why? (New Developer)
MewsData - A powerful datastore module
MewsData - A powerful datastore module
How do i create a saving system for parts using DataStores?
Is it possible to save the children of a folder with DataStore2?

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:

136 Likes

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

2023 edit : I’ve noticed folks still occasionally giving a like to this post. Datastore V2 APIs exist now with key versioning, you don’t need to version data yourself anymore!
https://create.roblox.com/docs/en-us/reference/engine/classes/DataStore#GetVersionAsync

161 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.

64 Likes

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

186 Likes

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

60 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!

56 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.

51 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!

40 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:

38 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.

37 Likes

Suggested by yours truly

39 Likes

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

34 Likes

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

41 Likes

I can look into it @Aorda @Beartikal.

35 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.

29 Likes

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

27 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:

37 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:

30 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.

38 Likes