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

Don’t use the master key as a key, ever. Use inventory or Stats. This is in the documentation

If you want the updated module, read the documentation, where it explicitly says how to get it.

1 Like

What should I do in the case of an HTTP 500 error? I thought that calling SetBackup would allow me to check if there is a problem with IsBackup, then handle it accordingly.

The recent outages have shown me that that’s not the case. Instead of flagging anything a backup, I just get an error. I want to kick the player if there’s an issue loading data.

Edit: I actually just did some testing and I found that I only get the error when using Standard saving method. After changing the saving method back to orderedbackups to test if my implementation of backups works, I’m still not getting kicked when I want to be.

This is the code that I’m using. This gets called as soon as the player joins:

function Level.GetPlayerData(player, data)
	local store = DataStore2("CombatScore", player)
	store:SetBackup(3)
	
	local current = store:Get(XpData.Default)
	print(store:IsBackup(), " is backup")
	if store:IsBackup() then player:Kick() end

	return current[data]
end

If I use this same code with standard saving method, I simply get an error. I thought using IsBackup would allow me to check if there was an issue retrieving data. With orderedbackups saving method, this code only returns the default value.

FYI: all testing that I’m talking about here was done during the roblox outage. I’m doing this testing because I simply want to kick players in future outages that affect datastores.

Is there item duplication in this datastore Module? I’m confused because I keep hearing people saying Datastore2 dupes items and some say that Datastore2 does not dupe items.

It only “dupes items” if your code lets it. There are ways to create safe trading (no duping items, no losing items) without session locks.

@Kampfkarren what are the benefits of using GetTable instead of Combine

i have some problems with using DataStore2 :Get() doesn’t works always like work 2/3 times (In Studio)

How would I make a datastore that isn’t tied to the player? I trying to make a server browser.

i think the better way to make Server Browser isn’t DataStore2 but the new MemoryStore Service

2 Likes

What is MemoryStore Service and how would I use it?

Very Great Module, Saves A Lot Of Data In DataStore

In order for me to know how to use this module correctly, can I have it save when a Save button is pressed rather than having my attributes constantly changing?

Hello, I have a system where all my data is saved into a dictionary. Any one help?

I have a question, idk if this was asked before but,

What does datastore2 do to prevent data loss?

What’s the best way to handle data loss prevention while using TeleportService with this module?

DataStore2 only saves when the player leaves or you call :Save(). I don’t think a player given save button is needed.

2 Likes

Call DataStore2.SaveAll before teleporting the players.

1 Like

okay thank you. Would this be fine to call immediately before I teleport them with TeleportService? Or should I save & lock the player into a teleport after a few seconds of saving?

Hello! I have a quick question, if I want to save a lot of data, for example an array, should I use Combined DataStore instead of GetTable method?

local Template = GetDataTemplate() -- returns all keys of DataTemplate table who i want to save
	self.DataStore = DataStore2.Combine(DataStoreName,unpack(Template))
	for i,v in ipairs(Template)do
		self.Data[i] = DataStore2(i,Player):Get(DataTemplate[i]) -- Default Value of each key
	end

To be more specific, my question is if this is good practice.

Thanks for reading, I would appreciate an answer!

How do you insert the latest folder into Roblox Studio?

it doesnt save :frowning: i only have one key though but i still did datastore2.Combine(“AllData”) because I save it in a dictionary. I also have SaveOnStudio value true in server storage. please help