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

how to save a string value with Data Persistance ?[SOLVED]

Asked by 9 years ago

Script in workspace

function loada(player)
    if player.DataReady then 
        if player then
            wait()
            local score = player.Folder:GetChildren()
            for i = 1,#score do

                    local ScoreLoaded = player:LoadNumber(score[i].Name)
                    local ScoreLoaded2 = player:LoadString("DF")
                    wait()
                    if score[i].Name == "DF" then
                        player.Folder.DF.Value = ScoreLoaded2
                    end
                    if ScoreLoaded ~= 0 then
                        score[i].Value = ScoreLoaded
                    else

                    end
                end

            ----Load Inventory----
            local inventory = player:findFirstChild("Inventory")
            if inventory then
                local saved_inv = player:LoadInstance("Invent")
                if saved_inv then
                    for j,k in pairs(saved_inv:GetChildren()) do
                        k.Parent = inventory
                    end
                end
            end
            end
    end
    end
function onPlayerEntered(player)
    local Inventory = Instance.new("Folder")
    Inventory.Name = "Inventory"
    Inventory.Parent = player

    local leaderboard = Instance.new("Folder")
    leaderboard.Name = "Folder"
    leaderboard.Parent = player

    local Beli = Instance.new("IntValue")
    Beli.Value = 10
    Beli.Name = "Beli"
    Beli.Parent = leaderboard

    local Trys = Instance.new("IntValue")
    Trys.Value = 2
    Trys.Name = "Trys"
    Trys.Parent = leaderboard

    local DF = Instance.new("StringValue")
    DF.Name = "DF"
    DF.Parent = leaderboard

    local GotDF = Instance.new("IntValue")
    GotDF.Value = 0
    GotDF.Name = "GotDF"
    GotDF.Parent = leaderboard

    local SetDF = Instance.new("IntValue")
    SetDF.Value = 0
    SetDF.Name = "SetDF"
    SetDF.Parent = leaderboard

    local Scene = Instance.new("IntValue")
    Scene.Value = 1
    Scene.Name = "Scene"
    Scene.Parent = leaderboard



    player:WaitForDataReady()
    loada(player)
    wait()
end

function onPlayerLeaving(player)
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

script in startergui

player = script.Parent.Parent.Parent
function save()
    if player.DataReady then
        if player then
            local score = player.Folder:GetChildren()
            for i = 1,#score do
                if score[i].ClassName == "IntValue" then
                        player:SaveNumber(score[i].Name,score[i].Value)
                        if score[i].Name == "DF" then
                        player:SaveString(score[i].Name,score[i].Value)
                        end
                end
                end
            if pcall(function()  player:SaveInstance("Invent", player.Inventory)  end) then
                script.Parent.Inventory.Button.Text = "Saved!"
                wait(1)
                script.Parent.Inventory.Button.Text = "Save"
            end
        end

    end
end
script.Parent.Inventory.Button.MouseButton1Click:connect(save)

while true do
    wait(300)
    save()
end

Answer this question