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

How to get my save system to save?

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

end)

game:BindToClose(function()
    for _,plr in pairs(game.Players:GetPlayers()) do
        dataStore:SetAsync(plr.UserId, plr.leaderstats.Time.Value)
    end   
end)

API Services are also activated, dont know why this isn't saving, as there is no errors.

1 answer

Log in to vote
0
Answered by
oSudden 20
3 years ago
Edited 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" points.Value = dataStore:GetAsync(plr.UserId) or 0 points.Parent = leaderstats -- Here's where you actually messed up, running a while loop pauses the whole thread. Using spawn function creates a separate thread to run the loop. spawn(function() while true do wait(1) points.Value = points.Value + 1 end end) end) game:BindToClose(function() for _,plr in pairs(game.Players:GetPlayers()) do dataStore:SetAsync(plr.UserId, plr:WaitForChild('leaderstats'):WaitForChild('Time').Value) end end)

Hope this helps!

Ad

Answer this question