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

How can i link the playerremoving in bindtoclose to save players data in playerremoving on shutdown?

Asked by 5 years ago

becourse im the only player and last player in my server to test it. it wont save my coins or gold or what ever. i even say print save in output but he even dont show that when i get out the game, so what am i doin wrong? and if u fand any other errors please let me know. thnx alot already

game.Players.PlayerRemoving:Connect(function(player)

    local Character = player:WaitForChild("Character")
    local LStats = player:WaitForChild("leaderstats")
    local BackPack2 = player:WaitForChild("BackPack2")
    local BackPack3 = BackPack2:WaitForChild("BackPack3")
    local Ranking = player:WaitForChild("Ranking")
    local Bank = player:WaitForChild("Bank")

    print("Saving Player Data - ".. player.Name)

    local IDForPlayer = "Stats-"..player.UserId

    local level

    if BackPack2.Helper.Value == true then

        level = Character:FindFirstChild("Helper").Level

    else

        level = 1
    end

        local stats = {
            Coins = LStats.Coins.Value;
            Gold = LStats.Gold.Value;
            Sand = BackPack3.Sand.Value;
            Stone = BackPack3.Stone.Value;
            MGold = BackPack3.MGold.Value;
            BankValue = LStats.Bank.Value;
            BankCoins = Bank.BankCoins.Value;
            BankGold = Bank.BankGold.Value;
            Rebirth = LStats.Rebirth.Value;
            BackPackMaxValue = BackPack2.BackPack3MaxValue.Value;
            Hammer = BackPack2.Hammer.Value;
            PickAxe = BackPack2.PickAxe.Value;
            Helper = BackPack2.Helper.Value;
            HelperLevel = level;
            Rank = Ranking.Rank.Value
        }

    ServerData:SetAsync(IDForPlayer, stats)

    print (player.Name.." Data Saved")
end)

game:BindToClose(function(player)
    game.Players.PlayerRemoving(player)
end)

1 answer

Log in to vote
1
Answered by 5 years ago

Well first of all I wouldn't put the .PlayerRemoving(Player) event inside game:BindToClose

try something more likes this:


local function SaveData(player) local Character = player:WaitForChild("Character") local LStats = player:WaitForChild("leaderstats") local BackPack2 = player:WaitForChild("BackPack2") local BackPack3 = BackPack2:WaitForChild("BackPack3") local Ranking = player:WaitForChild("Ranking") local Bank = player:WaitForChild("Bank") print("Saving Player Data - ".. player.Name) local IDForPlayer = "Stats-"..player.UserId local level if BackPack2.Helper.Value == true then level = Character:FindFirstChild("Helper").Level else level = 1 end local stats = { Coins = LStats.Coins.Value; Gold = LStats.Gold.Value; Sand = BackPack3.Sand.Value; Stone = BackPack3.Stone.Value; MGold = BackPack3.MGold.Value; BankValue = LStats.Bank.Value; BankCoins = Bank.BankCoins.Value; BankGold = Bank.BankGold.Value; Rebirth = LStats.Rebirth.Value; BackPackMaxValue = BackPack2.BackPack3MaxValue.Value; Hammer = BackPack2.Hammer.Value; PickAxe = BackPack2.PickAxe.Value; Helper = BackPack2.Helper.Value; HelperLevel = level; Rank = Ranking.Rank.Value } ServerData:SetAsync(IDForPlayer, stats) print (player.Name.." Data Saved") end game.Players.PlayerRemoving(function(player) SaveData(player) end) game:BindToClose(function(player) SaveData(player) end)
0
Wouldn't you loop through all the players in the BindToClose function? PhantomVisual 992 — 5y
0
thnx ur right. i looped through all the players on bindtoclose and this is what i needed. thnx for the help User#27824 0 — 5y
Ad

Answer this question