Showing successful loads and successful save prints, but the only 2 variables that will load in are "Gems" and "Stage". Even weirder, i have a shop that changes the values for the items in the table, it uses gems and changes the values of the items to true. This works perfectly, but after leaving the game and reloading, it deletes any trace of those purchases and the gems are back to their initial amount. Im beyond confused.

local PlayerSavedStuff = game:GetService('DataStoreService'):GetDataStore("PlayerSaveSystem")
local RunService = game:GetService("RunService")
local db = 3

function SaveTableFunc(player)
    local SaveTable = {
        Gems = player.PlayerSave.Gems.Value,
        Skips = player.PlayerSave.Skips.Value,
        boombox = player.PlayerSave.boombox.Value,
        doublejump = player.PlayerSave.doublejump.Value,
        gravcoil = player.PlayerSave.gravcoil.Value,
        hoverboard = player.PlayerSave.hoverboard.Value
        Stage = player.leaderstats.Stage.Value
    }
    return SaveTable
end

game.Players.PlayerAdded:connect(function(player) 
    repeat wait() until player.Character
    repeat wait() until script:FindFirstChild("PlayerSave")
    repeat wait() until script:FindFirstChild("leaderstats")
    local save1 = script.PlayerSave:Clone()
    local save2 = script.leaderstats:Clone()
    save1.Parent = player
    save2.Parent = player
    local PS = player.PlayerSave
    local LS = player.leaderstats
    local save = SaveTableFunc(player)
    local playerkey = "player-"..player.userId
    local SaveFiles = PlayerSavedStuff:GetAsync(playerkey)
    function dataInput(player, save)
          PS.Gems.Value = SaveFiles.Gems
          PS.Skips.Value = SaveFiles.Skips
          PS.boombox.Value = SaveFiles.boombox
          PS.doublejump.Value = SaveFiles.doublejump
          PS.gravcoil.Value = SaveFiles.gravcoil
          PS.hoverboard.Value = SaveFiles.hoverboard
          LS.Stage.Value = SaveFiles.Stage
          print("Got saved data for "..player.Name)
    end
    local Passed, Error = pcall(function() 
            if SaveFiles == nil then
                print(player.Name.." has no save data yet")
            else
		dataInput(player, save)
            end
    end)
    if Error then
        print("***ERROR GETTING SAVE FILE FOR "..player.Name)
        local attempts = 0
        while wait(db) do
            local retries = attempts + 1
            attempts = retries
            local pass,err = pcall(function()
            if SaveFiles == nil then
                print(player.Name.." has no save data yet")
	    else
		dataInput(player, save)
            end
      end)
            if pass or attempts == 5 then break end
        end
    end
end)

function SaveData(player)
    local Success,Error = pcall(function()
        local playerkey = "player-"..player.userId
        local save = SaveTableFunc(player)
        PlayerSavedStuff:SetAsync(playerkey,save)
        print("Saved data for "..player.Name)
    end)
    if Error then
        print("***ERROR SAVING DATA FOR "..player.Name)
        local attempts = 0
        while wait (db) do
            local retries = attempts + 1
            attempts = retries
            local pass,fail = pcall(function()
                local playerkey = "player-"..player.userId
                local data = SaveData(player)
                PlayerSavedStuff:SetAsync(playerkey,save)
                print("Successfully saved data for "..player.Name)
            end)
            if pass or attempts == 10 then break end
        end
    end
end

game.Players.PlayerRemoving:Connect(SaveData)

game:BindToClose(function() 
    if RunService:IsStudio() then return end
    local Players = game:GetService("Players")
    for _,player in pairs(Players:GetPlayers()) do
        SaveData(player)
        print("Saved data for "..player.Name.." on shutdown.")
    end
end)

2 comments

0

Please indent ur code properly fffffffffffffffffffffff

0

Ill indent it perfectly if you tell me what i did wrong.