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
i found it out. remove the pointval and cashval variables as they aren't needed replace your pcall command with the one below (its indented wrong, i know)
local success, err = pcall(function() print("Save1") ds:UpdateAsync(player.UserId,function(pointval) local newval = points.Value print(newval) return newval end) print("Save2") ds2:UpdateAsync(player.UserId,function(cashval) local newval2 = cash.Value print(newval2) return newval2 end) print("Finished") end)