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

I actually cannot wait to use this. A few players have suffered from data loss in my games before, it was only 1 or 2 people, but they made a lot of progress.

How do i save colors or images using datastore2?

Is it worth using Datastore2? I was told that roblox has already fixed the issues Datastore2 was created for so why shouldn’t just use roblox’s datastore, thanks.

1 Like

It depends. If the color is a Color3, then you can serialize it. And in order to save images, it depends on what the image is. If it’s a decal, then you just save it’s ImageId in the datastore. But if it’s an image that a player can draw, then you will have to figure out a way to save the pixel data. You could do this by storing the color of every single pixel in the datastore, you could also compress the data too, so it can fit nicely into the datastore.

Here’s how you can serialize a Color, assuming it’s a Color3:

function encodeRGB(color3)
    return {color3.R, color3.G, color3.B}
end

function decodeRGB(encodedColor3)
    return Color3.fromRGB(encodedColor3[1], encodedColor3[2], encodedColor3[3])
end
1 Like

Hello, I’ve been experiencing an issue with ds2 for a bit now and i can’t seem to find a fix
So basically i made this module script to save the data


it works and all but at some unknown point, without erroring or any warnings the data just breaks and then it stops saving and people only realize when they rejoin, any ideas on the issue here?

1 Like

is there a way to force a player’s data to load?
You have to pass the player object, but i cant do that if the player is offline

Hey I have been having data loss for some of my players

The code that I am following is this because this is the only code that saves Dictionary in One key

-- Services
local players = game:GetService("Players")
local dataStore2 = require(1936396537)
local userDataStoreName = "UserDataStore"

--Get data (retrieves previous data or sets-up new data using the setupUserData function)
local function setupUserData()
	local userData = {
	}
	return userData
end
local userData = dataStore2(userDataStoreName, player):Get(setupUserData())

--Modify data
userData["Currency"]["Gems"] = 9999

--Set data
dataStore2(userDataStoreName, player):Set(userData)

As stated in the documentation, do not require DataStore2 by its ID.

2 Likes

what is your saving method i do not know can u tell me what is your method

1 Like

i mean like how to save guis like pet gui or something else

1 Like

is there a way i can use combine without loose data?

I’m very new to datastores, so I was wondering; how is :GetAsync() only called once, being that it’s only called the first time you use the module?

Roblox has openly mentioned DataStore2 being an outdated method of saving on Roblox. Developers liked this method previously because it supported data versioning. New updates to data store API have added versioning and more great changes. Data Stores | Documentation - Roblox Creator Hub

1 Like

I believe you are referring to the OrderedBackups type of store.

Not sure what an OrderedBackups type of store is. But the structure behind DataStore2 involves using ordered datastore to maintain the most recent save version and the key related to the save to avoid data overwriting.

This is considered legacy and is explicitly recommended against in the DataStore2 documentation.

It is no longer recommended. Please use the standard data store type instead, which does not provide the legacy versioning features.

I thought I saw a post regarding it earlier in this thread, but sadly I could not locate it.

how do I use .combine with multiple scripts? Do I run the combine code in every single script or make a server script just for combining and should the data scripts wait for it to combine?

1 Like

Hey! I’ve only just been starting to use this. I’ve ran into an issue though.

Using the DataStore2 Module, I added new lines right below the SaveInStudio check in the SaveAsync() function.
I want to make it so that DataStore2 does not save if a certain bool value is on. For some weird reason it only detects what the bool’s value is when the server starts. Changing the bool mid-game and then leaving still makes it save data. Is there a way to fix this?

Here’s the code if it’s needed:

local DataDisabledObject = ServerStorage:FindFirstChild("AbleToSaveData")
local DataDisabled = DataDisabledObject and DataDisabledObject.Value


if not DataDisabled then
	warn(("Data store %s attempted to save, however AbleToSaveData was disabled."):format(self.Name))
	if not DataDisabledObject then
		warn("Data Disabler isn't in ServerStorage. Data functionality can possibly be bad.")
	end
	resolve(false)
	return
end

While I may not consider myself an expert in scripting, I found DataStore2 to be significantly more straightforward than utilizing profileservice. Moreover, the setup process was remarkably simple for me. This is just my opinion but profileservice is way too complicated for most people like me that are just starting to script so for anyone looking for an alternative this is a great choice!