Datastores not working

I’m using the code bellow to save Players data to a datastore, but its not working.

local dataStore = game:GetService("DataStoreService"):GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.UserId
	local save1 = plr.leaderstats.Cash
	local save2 = plr.leaderstats.Rank
	local GetSaved = dataStore:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
	else
		local NumberForSaving = {save1.Value,save2.Value}


		dataStore:GetAsync(plrkey, NumberForSaving)

	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	dataStore.SetAsync("id_"..plr.UserId, {plr.leaderstats.Cash.Value, plr.leaderstats.Rank.Value})

end)

That should be a colon as it is a method of the DataStore.
Like this:

dataStore:SetAsync()

I also suggest wrapping it in a pcall so you can retry to get data if you failed and make sure you do not overwrite their data with nothing if you did not originally get their data.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.