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

How come my saving script is not saving my data? There is not even errors, like, come on?

local ds = game:GetService("DataStoreService"):GetDataStore("BigTycoonData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save = plr.leaderstats.Cash
	
	local GetSaved = ds:GetAsync(plrkey)
	if GetSaved then
		save.Value = GetSaved
	else
		local NumberForSave = {save.Value}
		ds:GetAsync(plrkey, NumberForSave)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Cash.Value})
end)

This is my saving data script. The leaderstats is fine, and has nothing but leaderstats. I get no errors in the client or server developer thing. Why isnt this saving?

3 comments

0

the title, the website hates

0

is api service on

0

yea

2 answers

GlobalDataStore:SetAsync() and GlobalDataStore:GetAsync() sometimes go down. You have to use a pcall(function() to stop the error from breaking the script.

local ds = game:GetService("DataStoreService"):GetDataStore("BigTycoonData")
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local plrkey = "id_"..plr.userId
    local save = plr.leaderstats.Cash

    local GetSaved

    local success, err = pcall(function() -- pcall
	  GetSaved = ds:GetAsync(plrkey)
    end)

    if GetSaved then
        save.Value = GetSaved
    else
        local NumberForSave = {save.Value}

	local success, err = pcall(function() -- pcall2
             ds:GetAsync(plrkey, NumberForSave)
       end)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local success, err = pcall(function() -- pcall3
        ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Cash.Value})
    end)
end)

Accept this if it fixed it.

Note: Click view source when hovering over the code, so the copying will be easier.

1 comment

0

doesnt have any errors, i tried it in roblox player and in studio, does not work

It probably is working, it's just that on Roblox Studio the Data Store Service can not be accessed without turning on the API Service setting in Game Settings. You should try your script In-Game to check if it works there or you could just turn on API Service to make it work on Roblox Studio. However I do not recommend turning it on. Final answer: try it in-game and come back if it does not work.

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