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 game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = plr local points = Instance.new("IntValue") points.Name = "Time Spent" points.Value = dataStore points.Parent = leaderstats while true do wait(1) points.Value = points.Value + 1 end end) game.Players.PlayerRemoving:Connect(function(plr) dataStore:SetAsync(plr.UserId, plr.leaderstats.points.Value) end)
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)
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.
^^^ 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