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

My leaderboard script doesn't create the folder I want and doesn't save the data?

Asked by 6 years ago
Edited 6 years ago

So I'm trying to store some values, they're boolean values. In a nutshell: they are there to determine whether the player owns a certain weapon or not.

of course I want to save this data, so to do that I came up with the following script:

local plyrdatalist = game.ServerScriptService.PlayerData:GetChildren() --This is a folder in ServerScriptService that contains a copy of all the boolean values that should be in the player.

CashKey = "PlayerCash"

game.Players.PlayerAdded:connect(function(player)
    if player:WaitForDataReady() then
        -- create leaderboard
        local ls = Instance.new("IntValue")
        ls.Name = "leaderstats"
        ls.Parent = player

        --create the Cash stat
        local Cash = Instance.new("IntValue")
        Cash.Name = "Cash"
        Cash.Parent = ls
        Cash.Value = player:LoadNumber(CashKey)

        local KillCount = Instance.new("IntValue")
        KillCount.Name = 'Kills'
        KillCount.Value = 0
        KillCount.Parent = player.leaderstats

        local PlayerData = Instance.new("Folder") --This is the folder that should contain the boolean values
        PlayerData.Name = "PlayerData"
        PlayerData.Parent = player.leaderstats


        for i = 1, #plyrdatalist do --This is where I try to make those values
            local WeaponBool = Instance.new("BoolValue")
            WeaponBool.Name = plyrdatalist[i].Name
            WeaponBool.Value = player:LoadBoolean(plyrdatalist[i].Name)
            WeaponBool.Parent = player.leaderstats.PlayerData
        end
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if player:FindFirstChild("leaderstats") then
        player:SaveNumber(CashKey, player.leaderstats.Cash.Value)
        for i = 1, #plyrdatalist do --This is where I try to save the values
            player:SaveBoolean(plyrdatalist[i].Name, player.leaderstats.PlayerData[plyrdatalist[i].Name].Value)
        end 
    end
end)

Right now, it does save cash, but when none of the boolean values get copied into the folder. There is just an empty folder in leaderstats. I did test this in-game, not in Studio.

All help is welcome. C:

0
Try putting a text to true or false, in a string value, instead of bool, then convert those text to a Bool. thesit123 509 — 6y
0
tl;dr OrcaTheFish 95 — 6y
0
Wow, it's actually really stupid. I just had to add a little WaitForChild("PlayerData") in the beginning. Everything works. Thanks for your help thesit123 anyway. And @OrcaTheFish: if you didn't even take the time to read it, then don't comment. blacksmiley0 19 — 6y

Answer this question