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

Data store script not saving, what can I add to fix it?

I have API services turned on as well as http requests. I have even tried testing it outside Roblox Studio and inside the game on the website. Still, my data is not being saved. I have asked for help from multiple people and they don't know what the reason is. Thanks for any help.

The code I wrote is as follows...

local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")

-- Load Data

game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	local plrKey = "id_"..plr.userId
	local CashSave = plr.leaderstats.Cash
	
	local GetSaved = ds:GetAsync(plrKey)
	if GetSaved then
		CashSave.Value = GetSaved[1]
	else
		local NumberForSaving = {CashSave.Value}
		
		local success, errormessage = pcall(function()
			ds:GetAsync(plrKey, NumberForSaving)
		end)
		
		if success then
			warn("Data successfully loaded")
		else
			warn("Error when attempting to load data.")
		end
		
	end
end)

-- Save Data

game.Players.PlayerRemoving:Connect(function(plr)
	
	local success, errormessage = pcall(function()
		ds:SetAsync("id_"..plr.userid, {plr.leaderstats.Cash.Value})
	end)
	
	if success then
		warn("Data successfully saved.")
	else
		warn("Error when attempting to save data.")
	end
	
end)

2 answers

Hey, DaOtakuEthan!

On line 17 of your script, you're passing two arguments with :GetAsync(), which isn't possible. Looking at the API, we can see that :GetAsync() only requires one argument, which makes me think you meant to use :SetAsync() instead.

Firstly first, you did two arguments in ds:GetAsync(), which has only ONE value. Secondly second, does warn("Data successfully ___") warn? Comment down below what warns in the pcalls.

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