Hi guys! Any ideas why this doesn't save when the player leaves? I have an OnClose event to keep the game open for another 4 seconds which should be enough to save the data and it doesn't :/

Any help would be appreciated! Thanks :)

I get no errors in the output.


    for _, child in pairs(modelSeven:GetChildren()) do 
        for _, saved in pairs(utility:JSONDecode(tab)) do
            if rawequal(saved.Name, child.Name) then
                child.Value = saved.Value
            end
        end

game.Players.PlayerRemoving:connect(function(plr)
            local tab = {}

            for _, v in pairs(child.Parent:GetChildren()) do
                tab[#tab + 1] = {Name = v.Name, Value = v.Value}
            end

            local encoded = utility:JSONEncode(tab)
            dataStore:SetAsync(plr.userId, encoded)              
        end)
    end

game.OnClose = function()
    wait(4)
end

2 comments

0

How long is your script? If it's not massive, could you share the whole script so all variables are visible? Also,try using table.insert() instead of the method you're doing for 12, this could help.

0

The script is quite long :/ OK, thanks!