I've been trying to figure out datastores for a bit, and I've ran into a bit of an obstacle. I'm currently trying to save 2 values, cash and points. The remote is firing every 60 seconds and is being received ( can see from the print() ), but for some reason it doesn't save. The serverscript is parented to the localscript, and the localscript is inside the player's backpack. What am I doing wrong? edit: The serverscript is now in serverscriptservice, and the remote is in replicatedstorage.
--this is the serverscript
local remote = script.Parent:WaitForChild("reeeeee")
local datastore = game:GetService("DataStoreService")
local ds = datastore:GetDataStore('PointSaveSystem')
local ds2 = datastore:GetDataStore('CashSaveSystem')
remote.OnServerEvent:connect(function(player,message)
if message == 'SaveData' then
local points = player:WaitForChild('leaderstats'):WaitForChild('Points')
local cash = player:WaitForChild('leaderstats'):WaitForChild('Cash')
local cashval = cash.Value
local pointval = points.Value
local success, err = pcall(function()
ds:UpdateAsync(player.UserId,function(pointval)
local newval = pointval
newval = newval
print(newval)
return newval
end)
ds2:UpdateAsync(player.UserId,function(cashval)
local newval2 = cashval
newval2 = newval2
print(newval2)
return newval2
end)
end)
print('saved')
end
end)
--this is the localscript
local remote = script:WaitForChild("reeeeee")
while wait(60) do
remote:FireServer('SaveData')
end

18 comments
why not make the server script parented to serverscriptservice?
Thanks for replying! Sorry if I'm a bit slow to reply, I have to wait a minute to see the autosave results. I have put the serverscript in serverscriptservice and the remote in replicatedstorage, but I still have the same results of the values not saving.
what value is success returning?
and if false, what is err returning?
At the moment I do not have the pcall returning anything. The printed values I get are 18(which is the startvalue), nil, and 'saved'(from the end)
maybe as a test we can backup the server script and replace updateasync with setasync? I have no idea what update async is tbh
plus, updateasync is a yielding function so maybe its yielding forever?
I have been told that updatesync works better than setasync, as SetAsync does not queue the requests in order, which can lead to data loss.
ok but updateasync is a yielding function as in it will wait until the function/thread finished. do you think it is yielding forever?
I have a print after the UpdateAsync functions, so I don't think it's yielding forever.
do they print stuff?
Yes
im gonna test it quicikly
Kay
FINALLY!!! I FIGURED IT OUT
Amazarino! Could you share how?
posted it
try it though it may not work