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

Save script for time spent statistic isn't saving?

Asked by 3 years ago
local dataStore = game:GetService("DataStoreService"):GetDataStore("randommeusumtime")

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:GetAsync(plr.UserId)
    points.Parent = leaderstats
    while true do
        wait(1)
        points.Value = points.Value + 1
    end

end)

game:BindToClose(function(plr)

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

end)

Tried a million times now, save scripts never work. HELP PLZ LOL???

0
The way you are saving the data is not correct. First of all, BindToClose() does not run in Studio. Secondly, you are saving data using :SetAsync() you are not loading the data properly whist using :GetAsync(). Soban06 410 — 3y

Answer this question