Data store doesn't save

I believe if you have created the PlayerRemoving and BindToClose functions properly, it should work. Could you post your lastest code after you make the changes?

The problem is that you just set the value to a dictionary containing the values, not the saved value it self. Since you save cash inside data, you would have to index cash inside the dictionary since dictionary are key-value pairs.

int.Value = data.Cash

If you print data, it would print the memory address at where it is located.

Now your telling me to use 2 functions at the same time. Iā€™m very confused now.

Sorry, I donā€™t understand what youā€™re trying to say. Iā€™ve learnt from other youtubers and they did the same thing as well.

You need to comprehend what each line is for, you probably just copied the code. You have to access cash inside the dictionary which you saved. Try it out for your self.

Have you read my earlier replies?..

Because I have clearly told that both the functions do something different, read them again if you can please. So yes, you should use them both.

Iā€™m just going to test if it works whenever a player leaves, not to also test if it works whenever the server is shut down.

That is from the data store, how can I access the dictionary?

You are accessing the dictionary but not the value you saved inside it. You can use the . operator to access what you saved which in your case, is cash.

int.Value = data.Cash --// since the whole dictionary is saved, the values are too!

So is it this?

int.Value = data.Cash.Value

You donā€™t have to use .Value since dictionary are key value pairs and you already set Cash to itā€™s value. So it would be: int.Value = data.Cash

But Iā€™m only saving one value, not multiples yet. So your telling me this can be used for solo and multiple values?

Yes, you would have to set each value to the value in the saved dictionary.

Thanks, I will try your and Jamesā€™ method later.

Just to clear out, his solution is probably what you want to use for your script as you are just testing. What I suggested is using BindToClose for saving too, so that you donā€™t have data loss errors in Server Shut down events.

So your telling me that his script wonā€™t work for atcual gameplay?

Where in my reply did I say that? What I meant is that his solution is what you want to use. It will work even if you use that script for actual gameplay.

You can go ahead with testing the BindToClose method too if you want, I said you donā€™t need to use it in this script as you said you are just testing.

Just to not make you even mad and get pissed of by me, Iā€™m just gonna say you had brighten me up a lot. Thanks for the help.

1 Like

Hey, I tried his method and this is the errror.

image

Newest code:

local ds = DSS:GetDataStore("CashAndWins")
local run = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"
	
	local cash = Instance.new("IntValue",folder)
	cash.Name = "Cash"
	
	local id = plr.UserId
	
	local data
	local success, errormessage = pcall(function()
		data = ds:GetAsync(id)
	end)
	
	if success then
		print("Successfully obtain data!")
		cash.Value = data.Cash
	else
		warn("Failed to load ata.")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local id = plr.UserId
	
	local data = {
		Cash = plr.leaderstas.Cash.Value;
	}
	
	local sucess, err = pcall(function()
		ds:SetAsync(plr,data)
	end)
end)

To add on, I did not set a starting value to the new players. I donā€™t want it to have a starting value, any solution?

cash.Value = data.Cash

That is the error, why is it data.Cash and not simply data?

Edit: actually imma take a look again