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
so far i only know what you dont use
"id_"but instead you use"id-"