Making Secure and Safe Datastores

I’m curious to anyone out there, what are all the fail points of a Datastore process? I’m designing a Datastore module (open source in the future maybe??) and want to make sure that everything that can happen is accounted for. I’m aware of the general precautions, like using pcall() and whatnot, however, I’d like to know everything that can go wrong, and what goes on when it goes wrong.

1 Like

Everything should be in the Roblox developer page on datastore errors and limits: Documentation - Roblox Creator Hub

It also has all of the error codes that are related to Datastores, so it is a good reference for if there are any problems

Maybe too much data store requests could error the data store?

You can see what are the errors and limits here Documentation - Roblox Creator Hub

The ways to “counter” them are said in there too.

I’d recommend using DataStore2. It’s an opensource module that you can get here

Usage example:

local DATASTORE_KEY = “Development1” – You can change the key to whatever
local DataStore2 = require(script.Parent:WaitForChild(“DataStore2”))
DataStore2.Combine(DATASTORE_KEY, “PlayerData”)
– So this sets up DataStore2, once you do this then you’re ready for use.

In Order to save data, heres a sample code to get you started:

local DataToSave = {cash = PlayerCashValue, RoleplayName = PlayerRoleplayName}
DataStore2(“PlayerData”, self._obj):Set(DataToSave )
– you can use the code above everytime something changes, since it doesnt automatically datastores it, holds a copy of the data and then datastores it once player leaves or server ended to prevent data loss.

And if you want to retrieve the data, you just do the following:

local DataTemplate = {cash = 100, RoleplayName = “None”} – Default values for when user joins without anything saved.
local data = DataStore2(“PlayerData”, player):Get(DATA_TEMPLATE);
local LoadedCash = data.cash
local LoadedRoleplayName = data.RoleplayName

And that’s about it. It’s an efficient way of saving/loading data for big amount of players. I personally used it in numerous projects which have a lot of traffic.

1 Like

I personally recommend ProfileService It handles most of those nasty edge cases for you, and is super easy to implement.
It also has more uses than saving player data, like global updates.

1 Like

@KinqAndi
@TotallyTrustful
I explained I was making my own. Not using another person’s.

There are lots of caveats when making your own DataStore module - so many, in fact, that some of them are not even documented on the official Roblox API (And you certainly won’t have strangers on the forums list the entirety of them for you :smile:). I highly advise you to at the very least explore modules that were created by the community to get the grip of what it truly takes to make an efficient module - as Eryn, an Adopt Me software engineer, says: “Don’t make code that has already been written before if you want to be an efficient developer”.

There are already enough forum threads to do research on your own. Good luck.

1 Like

Alright, thanks. I’ll definitely take a look at some other modules. I did jump into this a bit too early, however, as I realized trying to make a serialization table without knowing what your game is going to contain is a bit, difficult.

1 Like