Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED]Why aren't my values saving?

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

0

why not make the server script parented to serverscriptservice?

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.

0

what value is success returning?

0

and if false, what is err returning?

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)

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

0

plus, updateasync is a yielding function so maybe its yielding forever?

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.

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?

0

I have a print after the UpdateAsync functions, so I don't think it's yielding forever.

0

do they print stuff?

0

Yes

0

im gonna test it quicikly

0

Kay

0

FINALLY!!! I FIGURED IT OUT

0

Amazarino! Could you share how?

0

posted it

0

try it though it may not work

1 answer

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)

6 comments

0

i had this problem before, it's because the values are nil when the variables are created i think

0

testing to see if this works rn ( and if it does how do i mark something as the answer? )

0

i dont know

0

heck, well, it works. thank you veeeeeery much!!

0

np

0

glag to help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.