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

Data Saving Script stopped saving data?

Asked by 5 years ago

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)
0
so far i only know what you dont use `"id_"` but instead you use `"id-"` Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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

0
The were no errors in the output Boi52893642864912 69 — 5y
Ad

Answer this question