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)
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