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

Data Saving Script stopped saving data?

I made a data save script, but it barely ever saves data (meaning it pretty much saves when it wants to). I am not sure why this is happening. Perhaps I messed up a line? API is on too, so I am pretty confused.

local DS = game:GetService("DataStoreService"):GetDataStore("pointsstore")
game.Players.PlayerAdded:Connect(function(p)
local folder = Instance.new("Folder")
folder.Parent = p
folder.Name = "leaderstats"
local points = Instance.new("IntValue")
points.Parent = folder
points.Name = "Points"
wait()
local plrKey = "id_"..p.userId
local GetSaved = DS:GetAsync(plrKey)
if GetSaved then
points.Value = GetSaved[1]
else
local NumbersForSaving = {
points.Value
}
DS:GetAsync(plrKey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(p)
DS:SetAsync("id_"..p.userId, {
p.leaderstats.Points.Value
})
end)

1 comment

0

so far i only know what you dont use "id_" but instead you use "id-"

1 answer

local DS = game:GetService("DataStoreService"):GetDataStore("pointsstore")

game.Players.PlayerAdded:Connect(function(p)
local folder = Instance.new("Folder")
folder.Parent = p
folder.Name = "leaderstats"
local points = Instance.new("IntValue")
points.Parent = folder
points.Name = "Points"
wait()
local plrKey = "id_"..p.UserId -- "userId" is Deprecated.
local GetSaved = DS:GetAsync(plrKey)
if GetSaved then
points.Value = GetSaved[1]
else
local NumbersForSaving = {points.Value}
DS:SetAsync(plrKey, NumbersForSaving) -- You put GetAsync
instead of "SetAsync".
end
end)

game.Players.PlayerRemoving:Connect(function(p)
DS:SetAsync("id_"..p.UserId,
{p.leaderstats.Points.Value})
end)

Firstly, you didn't appropiately write your variables correctly. Secondly, you using the wrong Async option for saving your data. Thirdly;

ALWAYS CHECK OUTPUT FOR ERRORS

1 comment

0

The were no errors in the output

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