Trouble with data store 2

Hi, I have a game where I’m trying to use data store 2 to save data but I’ve encountered a problem. It seems like it does save my stats in datastore 2, but when I rejoin my stats aren’t saved in the data store anymore. Here’s my script:

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local DataStore2 = require(script.MainModule)

DataStore2.Combine("DATA", "Wins")
DataStore2.Combine("DATA", "Cash")

Players.PlayerAdded:Connect(function(Player)
	--// Give the stats
	local Stats = Instance.new("Folder", Player)
	Stats.Name = "Stats"
	
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Wins = Instance.new("IntValue", leaderstats)
	Wins.Name = "Wins"
	
	local Cash = Instance.new("IntValue", leaderstats)
	Cash.Name = "Cash"	
	
	local Points = Instance.new("IntValue", Stats)
	Points.Name = "Points"	
	
	--// Refresh saved data
	local CashStore = DataStore2("Cash", Player)
	local WinsStore = DataStore2("Wins", Player)
	
    print(WinsStore:Get(0)
	Wins.Value = WinsStore:Get(0)
	Cash.Value = CashStore:Get(0)

	--// Update ds2
	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		CashStore:Save(Cash.Value)
		print(CashStore:Get(0))
	end)

	Wins:GetPropertyChangedSignal("Value"):Connect(function()
		WinsStore:Save(Wins.Value)
		print(WinsStore:Get(0))
	end)
end) 

(I save certain stuff in a folder named Stats because I don’t want certain stuff to show in the leaderboards)

So when my win value changes the getpropertychangedsignal function seems to work, it prints whatever my wins value is, so that means it has saved my wins successfully. However when I rejoin it sets my wins value to 0, as if I’ve never saved anything in the datastore, but I definitely have. It seems like it just clears the data store when I leave.

Are you inside studio? If so make sure you have DataStore2’s save data in studio option enabled.

1 Like

I’ve enabled access to http services in the game settings if that’s what you mean. If it weren’t enabled I’m pretty sure it wouldn’t save the value in the first place, not save it and then “forget” it when I rejoin.

Edit: Nevermind I read your reply wrong, where would I go to enable ds2’s save data in studio option?

Here is the creator explaining it in their docs.

1 Like