1

# How to make auto-saving script that works (Not same guy below)?

Asked by 3 months ago
Edited 3 months ago

This script also adds 1 point per second. It's in sss. No errors.

Not saving somehow.

local dataStore = game:GetService("DataStoreService"):GetDataStore("randommeusumtime")

starterRolls = 0

local leaderstats = Instance.new("Folder")

local points = Instance.new("IntValue")
points.Name = "Time Spent"
points.Value = dataStore
while true do
wait(1)
points.Value = points.Value + 1
end

end)

game.Players.PlayerRemoving:Connect(function(plr)

end)


3
phxntxsmic 2232
3 months ago

Use game:BindToClose. When the server closes, there is a good chance that game.Players.PlayerRemoving will not fire, which would be why your script is not saving.

As OfficerBrah pointed out, you need to set the variable's value to the value from the datastore, not to the datastore itself:

points.Value = dataStore:GetAsync(plr.UserId)

0
Even after all your help, the script still wont save!! I dont get it. but good try on attempting to fix it. Jakob_Cashy 67 — 3mo
0
Vong25 237
3 months ago

The name of the IntValue is "Time Spent," but you are referencing it as "points."

dataStore:SetAsync(plr.UserId, plr.leaderstats["Time Spent"].Value)


Since there is a space in the instance name, you have to use [] to path it.

0
Answered by 3 months ago
Edited 3 months ago

^^^ yeah, you used the "points" variable to reference the IntValue you created inside the function, but the Name property is what the rest of your game sees

also on line 14, you set the value of the "Time Spent" IntValue to the datastore itself, rather than the data that is stored in the datastore. Replace it with this:

points.Value = dataStore:GetAsync(plr.UserId)


and I think it should work