How can I use the dataStore2?

Well, I decided to change the datastores of my game to DataStore2 since there is data loss in the normal DataStore, and according to the dataStore2 there is no data loss. The problem is the following script, I wrote it after seeing a tutorial, but it doesn’t save the data and I don’t know how this one works…

local Players = game:GetService("Players")

local DataStore2 = require(1936396537)

DataStore2.Combine("Data", "Money")

local defaultMoney = 65

Players.PlayerAdded:Connect(function(player)
	local Data_player = Instance.new("Folder", player); Data_player.Name = "other"
	local MoneyValue = Instance.new("IntValue", Data_player); MoneyValue.Name = "Money"

	local moneyStore = DataStore2("Money", player)

	local function UpdateMoney(money)
		player["other"].Dinero.Value = money
	end

	UpdateMoney(moneyStore:Get(defaultMoney))
	moneyStore:OnUpdate(UpdateMoney)
end)

Apparently it only works when entering the normal roblox, not the one in the study, so I add more amount to the value of the DataStore2 value and it does not save them.

Also sometimes the IntValue of the dataStore does not appear

First check the DataStore2 tutorial. To make values save on studio, you will need to create a BoolValue on ServerStorage, name it “SaveInStudio” and set its value to true.

1 Like

Ah I already found the error, sorry. I have a doubt, the dataStore2 is saved with the name of the player or with the UserId, it is that I do not see that it uses “player.UserId” to save the data, it only uses “player”