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

That isn’t the latest release. The free model is not updated anymore, and hasn’t been recommended in a long time. Please recheck the documentation.

Have you turned on API services? I had the same error, just forgot to turn it on.

Thanks for the reply!

Yes, I do have API services turned on. I am noticing that sometimes there are too many requests added to queue, but I am not sure what I’m doing to do that. Typically these warnings arise, followed by the HTTP 503 error, and then the Datastore failing to update.

I’m using :Set whenever data changes, but from what I read, this shouldn’t be the cause.

I’m using :Get() to get values and :Set() to change them.

Apologies for my potential lack of knowledge regarding DS2, but this issue really came out of no where and I’m stumped!

I am also getting errors of “503 Service Unavailable” for DataStore… and I don’t use DataStore2. Problems started happening about 1 day ago for no apparent reason. (My bad if I shouldn’t be posting this here). It also seems that the DataStore queue overfills too fast. It’s really odd.

I am also getting this error regarding "502: API Services rejected request with error HTTP 503 (service unavailable) causing user’s data to be wiped, I do not use DataStore2.

I made a separate thread here regarding HTTP 503 errors. This seems like an issue prevalent with both DS2 and non-DS2 users. Please post your experiences there if possible:

1 Like

hello, I have been working for a long time using the DataStore2 system, I basically already know how to use it, but lately a script of my “Quest” is not working before, it used to work normally …
it seems that for some reason it is not reading the increment part in the script, I can get the value of: Get () but I can’t change a value in the script using: Increment () and: Set ()

this is my script [Server Script] (It can be a bit confusing but I hope you can understand)

local DataStore2 = require(5159892169) --This is my module OBS: (Updated Version!)
local ConverValues = require(5084840082)

DataStore2.Combine("GameData_V1","Power","TotalPower","Rebirth")

local localplayer = script.Parent.Parent.Parent.Parent

--Remotes--
local Remote = script.RemoteEvent
local KilledDummy = game.ReplicatedStorage.Events.Giver_Event
local UpdatedPowerEvent = game.ReplicatedStorage.Events.Update_UIPower
local CompletedQuestEvent = game.ReplicatedStorage.Events.QuestCompletedEventGive
---------------

local QuestFrame = script.Parent.Parent.QuestFrame

local Kills = nil
local NumberKills = nil
local QuestDummy = nil
local DummyNameInQuest = nil
local GiverAmountPower = nil

local HaveQuest = false

Remote.OnServerEvent:Connect(function(player,DummyName,DummyNameQuest,ToKills,ValueToGive)
if player.Name == localplayer.Name then
local RebirthSave  = DataStore2("Rebirth",game.Players[player.Name])
QuestFrame:TweenPosition(UDim2.fromScale(1,0.95),'Out', 'Bounce', 1,true)
HaveQuest = true
GiverAmountPower = (tonumber(ValueToGive)*(RebirthSave:Get(0)+1))
QuestDummy = DummyName
DummyNameInQuest = DummyNameQuest
Kills = 0
NumberKills = ToKills
local TextQuest = "Kill "..ToKills.." "..DummyNameQuest.." to earn "..ConverValues:ConvertShort(GiverAmountPower)
QuestFrame.QuestInfo.Text = TextQuest
QuestFrame.QuestKills.Kill_Amount.Text = Kills.."/"..ToKills
QuestFrame.QuestKills.QuestBar.Size = UDim2.fromScale(0,1)
end
end)

function QuestFinished()
local random = math.random(250, 750)
local xnew = random / 1000
local new = script:WaitForChild("PowerGived"):Clone()
new.Text = "💪+".. ConverValues:ConvertShort(GiverAmountPower)
new.Position = UDim2.new(xnew, 0, 1, 0)
new.Parent = script.Parent.Parent
new:TweenPosition(UDim2.new(new.Position.X,0,0,0),'Out', 'Linear', 1)
QuestFrame:TweenPosition(UDim2.fromScale(1,1.95),'Out', 'Bounce', 1,true)
HaveQuest = false
GiverAmountPower = nil
QuestDummy = nil
DummyNameInQuest = nil
Kills = nil
NumberKills = nil
wait(4)
new:Destroy()
end

local function FinishQuest()
QuestFrame:TweenPosition(UDim2.fromScale(1,1.95),'Out', 'Bounce', 1,true)
wait()
HaveQuest = false
GiverAmountPower = nil
QuestDummy = nil
DummyNameInQuest = nil
Kills = nil
NumberKills = nil
end

script.FinishQuest.OnServerEvent:Connect(FinishQuest)

KilledDummy.Event:Connect(function(PlayerName,DummyKilledName)
if HaveQuest then
if PlayerName == localplayer.Name then
	if DummyKilledName == QuestDummy then
		Kills = Kills+1
		local TextQuest = "Kill "..NumberKills.." "..DummyNameInQuest.." to earn "..ConverValues:ConvertShort(GiverAmountPower)
		QuestFrame.QuestInfo.Text = TextQuest
		QuestFrame.QuestKills.Kill_Amount.Text = Kills.."/"..NumberKills
		local BarSize = Kills/NumberKills
		QuestFrame.QuestKills.QuestBar:TweenSize(UDim2.fromScale(BarSize,1),'In', 'Quint', 0.5, true)
		if Kills == NumberKills then
			local PowerSave  = DataStore2("Power",game.Players[PlayerName])
			local TotalPowerSave  = DataStore2("TotalPower",game.Players[PlayerName])
			PowerSave:Increment(GiverAmountPower,0) -- For some reason these lines are not being executed by datastore2
			TotalPowerSave:Increment(GiverAmountPower,0) -- For some reason these lines are not being executed by datastore2
			QuestFinished()
		end
	end
end
end
end)

this post has the ceritificate of awesome

@Kampfkarren
I discovered the problem that some players are “losing data” (IF IT LOOKS LIKE MY CASE), I was basically thinking that I was not saving my data, but after a while I found that if you call the function :Increment () or :Set () at the same time in two different scripts it will not save correctly, it has to have a cooling of at least 0.1 seconds, I did it in my script and it is working now !! I just don’t know why you’re not saving with two calls, because before I updated my module it was working normally, what I think is that something from the new update is interfering with that …
Hope this helps.
(Maybe this was just happening to me!)

1 Like

As stated by @Kampfkarren, the free model is not updated anymore. Please use the version from the link above, that says “Download”

Where can I find the paid version.

Please read the documentation. There is no paid version, just a new way of getting it.

so … just like i said before in the script … that module is updated, i downloaded it then export it to roblox.

I was looking through the threat to find posts related to GDPR Erasure and saw that you wrote:

clear(userId, name)

This is very helpful, but I’m a bit confused on what you meant by using this in the command bar? I have edited DS2 so that it can support NoLoading on top of NoSaving to simulate a new player, however, how would I use that command in the command bar? Would I need to copy and paste this into the command bar via Dev Console with userId being the players ID and name is the name of the stat (such as “Gold” or “Level”)?

Yes, that is how you can get the latest version.

Are you asking what the command bar is on Roblox Studio or how to use my code with the command bar?

1 Like

Hello ! I have just a small question for you, is this a good way to use DS2.Combine ? I heard u said that if we use more than 1 main key, we are missing the concept of combine. Would this code cause more memory to be taken by the game ? Do i abolutely need to put everything under 1 main key ?

DataStore.DS2 = require(1936396537)

DataStore.NewPlayerDataTable = {
	Slot1 = DataStore.NewCharacterDataTable, 
	Slot2 = DataStore.NewCharacterDataTable, 
	Slot3 = DataStore.NewCharacterDataTable,
	Slot = DataStore.NewCharacterDataTable,
    Settings = DataStore.SettingsDataTable,
    Parameters = DataStore.Parameters
}

DataStore.DS2.Combine("DATA", "Slots")
DataStore.DS2.Combine("Slots", "Slot1")
DataStore.DS2.Combine("Slots", "Slot2")
DataStore.DS2.Combine("Slots", "Slot3")
DataStore.DS2.Combine("Slots", "Slot")
DataStore.DS2.Combine("Slots", "Settings")
DataStore.DS2.Combine("Slots", "Parameters")

-- ... in another script ... --

-- this is runned the first time a player joins the game to set the table in the memory
local SlotsStore = DataStore.DS2("Slots", player)
SlotsStore:GetTable(DataStore.NewPlayerDataTable)
SlotsStore = nil

Thank for reading ! :slight_smile:

This is what you said in post 187, I’m not entirely sure what you meant by using said command in the command bar.

I believe you can just do this:

DataStore.DS2.Combine("DATA", "Slots","Slot1","Slot2","Slot3","Slot","Settings","Parameters")

The way your doing is fine too.

HOWEVER, this wouldn’t work because your requiring the old datastore2 module. This one isn’t the latest version, so you will need to get it from the GitHub page.

Have a good day!

1 Like

No, it isn’t. You should only have one master key, and you should never use the master key directly.

1 Like