Switching to DataStore2

Okay let me try that right now.


Okay I think I know why. I added a starter player script to get money once you kill someone. Also you earn money rom collecting coins and from zombies. Maybe that’s it? Or is it because of the script.

I don’t think that’s it. But I think I have the solution now! :smiley:

local defaultValue: number = 100 --If player has no data then their gold will be set to this value

local DataStore2 = require(1936396537)
DataStore2.Combine("MasterKey", "Gold")

game.Players.PlayerAdded:Connect(function(player)
	local goldData = DataStore2("Gold", player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local goldStat = Instance.new("IntValue", leaderstats)
	goldStat.Name = "Gold"

	local function UpdateStat()
		goldStat.Value = goldData:Get(defaultValue)
	end

	goldData:OnUpdate(function()
		UpdateStat()
	end)
	
	goldStat.Changed:Connect(function()
		if goldStat.Value > goldData:Get() then
			goldData:Set(goldStat.Value)
		end
	end)

    goldStat.Value = goldData:Get(defaultValue)
end)

This should fix it!

Okay let me try that rightnow.

I’m going to see how I did it in a game I made.

Okay also for some reason the DataStore2 in the gold saves a lot better than the one in the inventory

nvm working

So it works properly now???
It would be weird that it all of a sudden works

Okay I just wanted ot make sure for the Inventory Save, it doesn’t just save before I published it right? Because my friend bought something, left and did not get it back. Might be his lag but I have everything. Why is that?

I tesd ittwo times. I kno why. I think i kinda lagged out and I did no realize I had 0 goldthe wole time after i published.

It’s probably the fact you switched to DataStore2

Oh so will it save properly from now on?

Yes, it should definetly save from now on, let me know if you have any more trouble! :smiley:

Okay when will you download discord? Look forward to talking to you if I have more problems!

I might be able to download it on Monday or Tuesday

Kk send ur tag to me here so I can friend you or you cna friend me. My tag is Jeffy#2139

I think you are right, it is not working again.

I think there may be a script in your game that is interfering with it.