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.