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

Why is my save data script saving 1 value instead of 3?

Asked by 6 years ago

So, I was just finishing off some updates to my game and I have these values. Cash, EXP and Level. I just noticed that it only saves 1 value which is Cash.

Here is the script for the save data

local DSService = game:GetService('DataStoreService'):GetDataStore('DataStore')
game.Players.PlayerAdded:connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.userId
    local lstats = Instance.new('IntValue', plr)
    local savevalue =  Instance.new('IntValue')
    local savevalue2 =  Instance.new('IntValue')
    local savevalue3 =  Instance.new('IntValue')
    lstats.Name = 'leaderstats'
    savevalue.Parent = lstats
    savevalue2.Parent = lstats
    savevalue3.Parent = lstats
    savevalue.Name = 'Cash'
    savevalue2.Name = 'EXP'
    savevalue3.Name = 'Level'

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        savevalue.Value = GetSaved[1]
    else
        local NumbersForSaving = {savevalue.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)    


end)

and if you need the script for the values

game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("BoolValue",plr)
    stats.Name ="lstats"
    local currency1 = Instance.new("IntValue",stats)
    currency1.Name = 'Cash'
    local exp = Instance.new("IntValue",stats)
    exp.Name = 'EXP'
    local level = Instance.new("IntValue",stats)
    level.Name = 'Level'
     plr.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag ~= nil then
                if tag.Value ~= nil then
                    local stats1 = tag.Value:WaitForChild("leaderstats")
                    stats1["Cash"].Value = stats1["Cash"].Value + 35
                    local stats2 = tag.Value:WaitForChild("leaderstats")
                    stats2["EXP"].Value = stats2["EXP"].Value + 125
                        exp.Changed:Connect(function()
                        level.Value = math.floor(exp.Value / 1000)
end)          
                end
            end
        end)
    end)
end)

1 answer

Log in to vote
0
Answered by 6 years ago

I think because Savetable is just the Cash value only

Ad

Answer this question