Hey can someone please tell me why my stats save script isn't working?

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("KeysSaveSystem")
local ds2 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"
	local Keys = Instance.new("IntValue", folder)
	Keys.Name = "Keys"
	local cash = Instance.new("IntValue", folder)
	cash.Name = "Cash"
	
	Keys.Value = ds1:GetAsync(plr.UserId) or 0
	ds1:SetAsync(plr.UserId, Keys.Value)
	
	cash.Value = ds2:GetAsync(plr.UserId) or 0
	ds2:SetAsync(plr.UserId, cash.Value)	
	Keys.Changed:connect(function()
		ds1:SetAsync(plr.UserId, Keys.Value)
	end)
	
	cash.Changed:connect(function()
		ds2:SetAsync(plr.UserId, cash.Value)
	end)
end)
```.

When using datastore it’s best to wrap the call in a pcall()

local success, err = pcall(function()
	ds1:SetAsync(plr.UserId, Keys.Value)
end)

You can then check the result with success and if it failed you can check the error code with err

if not success then
	print("Datastore ErrorCode: "..err)
end

You can check the meaning of the error code here:
https://developer.roblox.com/en-us/articles/Datastore-Errors

1 Like

nope still nothing…

local ds = game:GetService(“DataStoreService”):GetDataStore(“SaveData”)
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = “id_”…plr.userId
local save1 = plr.leaderstats.Keys

local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
	save1.Value = GetSaved[1]
else
	local NumberForSaving = {save1.Value}
	ds:GetAsync(plrkey, NumberForSaving)
end

end)

game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(“id_”…plr.userId, {plr.leaderstats.Keys.Value})
end)

I’m not sure I understand what your problem is. The code in your original posts works.
I ran your code once (to create the datastore key for my player) I then modified the code and changed the default values to 99 instead of 0. When I ran the game again it read from the datastore and gave me my saved values (0) and not the 99 it would have done otherwise