Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[SOLVED]Why aren't my values saving?

Asked by 6 years ago
Edited 6 years ago

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
0
why not make the server script parented to serverscriptservice? the8bitdude11 358 — 6y
0
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. Creationil 5 — 6y
0
what value is success returning? the8bitdude11 358 — 6y
0
and if false, what is err returning? the8bitdude11 358 — 6y
View all comments (14 more)
0
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) Creationil 5 — 6y
0
maybe as a test we can backup the server script and replace updateasync with setasync? I have no idea what update async is tbh the8bitdude11 358 — 6y
0
plus, updateasync is a yielding function so maybe its yielding forever? the8bitdude11 358 — 6y
0
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. Creationil 5 — 6y
0
ok but updateasync is a yielding function as in it will wait until the function/thread finished. do you think it is yielding forever? the8bitdude11 358 — 6y
0
I have a print after the UpdateAsync functions, so I don't think it's yielding forever. Creationil 5 — 6y
0
do they print stuff? the8bitdude11 358 — 6y
0
Yes Creationil 5 — 6y
0
im gonna test it quicikly the8bitdude11 358 — 6y
0
Kay Creationil 5 — 6y
0
FINALLY!!! I FIGURED IT OUT the8bitdude11 358 — 6y
0
Amazarino! Could you share how? Creationil 5 — 6y
0
posted it the8bitdude11 358 — 6y
0
try it though it may not work the8bitdude11 358 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
0
i had this problem before, it's because the values are nil when the variables are created i think the8bitdude11 358 — 6y
0
testing to see if this works rn ( and if it does how do i mark something as the answer? ) Creationil 5 — 6y
0
i dont know the8bitdude11 358 — 6y
0
heck, well, it works. thank you veeeeeery much!! Creationil 5 — 6y
View all comments (2 more)
0
np the8bitdude11 358 — 6y
0
glag to help :) the8bitdude11 358 — 6y
Ad

Answer this question