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

I have a question about DataStores? Its changing the values when you rejoin?

Asked by 8 years ago

Alright so the data store is supposed to save all your data and Im making a test with it to were if the Boolean is true then I need it to fire the if statement, but instead whenever you join, all your data is completely changed. You can see what I mean here, Only used the lemonade one, its supposed to save your data how it is and reload it but instead it changes the values. Just use if for a few seconds then rejoin and you'll know what I am talking about. Link to game Heres the if statement. As you can tell, its supposed to put all your values back in the same place

if(saves.saveLemonade.Value == true) then
        plr.PlayerGui.Game.Frame.Lemonade.Buy.Visible = false
        plr.PlayerGui.Game.Frame.Lemonade.MakeCash.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.MakeCash.MPC.Value = saveLemonadeCPC.Value
        plr.PlayerGui.Game.Frame.Lemonade.MakeCash.WaitTime.Value = saveLemonadeWaitTime.Value
        plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Level.Value = saveLemonadeLevel.Value
        plr.PlayerGui.Game.Frame.Lemonade.Upgrade.UpgradeCost.Value = saveLemonadeUpgradeCost.Value
        plr.PlayerGui.Game.Frame.Lemonade.CPC.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.Level.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.WT.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.CPC.Text = "Cash Per Click: "..saveLemonadeCPC.Value
        plr.PlayerGui.Game.Frame.Lemonade.Level.Text = "Level: "..saveLemonadeLevel.Value
        plr.PlayerGui.Game.Frame.Lemonade.WT.Text = "Wait Time: "..saveLemonadeWaitTime.Value.." Second"

Heres the full data store code.

local DSService = game:GetService('DataStoreService'):GetDataStore('AdVentureCapOfficialDataStore')
game.Players.PlayerAdded:connect(function(plr)
    local uniquekey = 'id-'..plr.userId
    local leaderstats = Instance.new('IntValue', plr)
    leaderstats.Name = 'leaderstats'
    local saves = Instance.new('IntValue', plr)
    saves.Name = "saves"
    local savevalue =  Instance.new('NumberValue')
    savevalue.Parent = leaderstats
    savevalue.Name = 'Cash'
    savevalue.Value = 1
    local saveLemonade = Instance.new('BoolValue')
    saveLemonade.Name = "saveLemonade"
    saveLemonade.Parent = saves
    local saveLemonadeLevel = Instance.new('IntValue')
    saveLemonadeLevel.Name = "saveLemonadeLevel"
    saveLemonadeLevel.Parent = saves
    local saveLemonadeCPC = Instance.new('NumberValue')
    saveLemonadeCPC.Name = "saveLemonadeCPC"
    saveLemonadeCPC.Parent = saves
    local saveLemonadeWaitTime = Instance.new('NumberValue')
    saveLemonadeWaitTime.Name = "saveLemonadeWaitTime"
    saveLemonadeWaitTime.Parent = saves
    local saveLemonadeUpgradeCost = Instance.new('NumberValue')
    saveLemonadeUpgradeCost.Name = "saveLemonadeUpgradeCost"
    saveLemonadeUpgradeCost.Parent = saves
    local saveNewsPaper = Instance.new('BoolValue')
    saveNewsPaper.Name = "saveNewsPaper"
    saveNewsPaper.Parent = saves
    local saveNewsPaperLevel = Instance.new('IntValue')
    saveNewsPaperLevel.Name = "saveNewsPaperLevel"
    saveNewsPaperLevel.Parent = saves
    local saveNewsPaperCPC = Instance.new('NumberValue')
    saveNewsPaperCPC.Name = "saveNewsPaperCPC"
    saveNewsPaperCPC.Parent = saves
    local saveNewsPaperWaitTime = Instance.new('NumberValue')
    saveNewsPaperWaitTime.Name = "saveNewsPaperWaitTime"
    saveNewsPaperWaitTime.Parent = saves
    local saveNewsPaperUpgradeCost = Instance.new('NumberValue')
    saveNewsPaperUpgradeCost.Name = "saveNewsPaperUpgradeCost"
    saveNewsPaperUpgradeCost.Parent = saves
    local saveCarWash = Instance.new('BoolValue')
    saveCarWash.Name = "saveCarWash"
    saveCarWash.Parent = saves
    local saveCarWashLevel = Instance.new('IntValue')
    saveCarWashLevel.Name = "saveCarWashLevel"
    saveCarWashLevel.Parent = saves
    local saveCarWashCPC = Instance.new('NumberValue')
    saveCarWashCPC.Name = "saveCarWashCPC"
    saveCarWashCPC.Parent = saves
    local saveCarWashWaitTime = Instance.new('NumberValue')
    saveCarWashWaitTime.Name = "saveCarWashWaitTime"
    saveCarWashWaitTime.Parent = saves
    local saveCarWashUpgradeCost = Instance.new('NumberValue')
    saveCarWashUpgradeCost.Name = "saveCarWashUpgradeCost"
    saveCarWashUpgradeCost.Parent = saves
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        savevalue.Value = GetSaved[1]
        saveLemonade.Value = GetSaved[1]
        saveLemonadeLevel.Value = GetSaved[1]
        saveLemonadeCPC.Value = GetSaved[1]
        saveLemonadeWaitTime.Value = GetSaved[1]
        saveLemonadeUpgradeCost.Value = GetSaved [1]
        plr.PlayerGui.Game.Frame.CASH.Text = plr.leaderstats.Cash.Value.."$"
        if(saves.saveLemonade.Value == true) then
        plr.PlayerGui.Game.Frame.Lemonade.Buy.Visible = false
        plr.PlayerGui.Game.Frame.Lemonade.MakeCash.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.MakeCash.MPC.Value = saveLemonadeCPC.Value
        plr.PlayerGui.Game.Frame.Lemonade.MakeCash.WaitTime.Value = saveLemonadeWaitTime.Value
        plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Level.Value = saveLemonadeLevel.Value
        plr.PlayerGui.Game.Frame.Lemonade.Upgrade.UpgradeCost.Value = saveLemonadeUpgradeCost.Value
        plr.PlayerGui.Game.Frame.Lemonade.CPC.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.Level.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.WT.Visible = true
        plr.PlayerGui.Game.Frame.Lemonade.CPC.Text = "Cash Per Click: "..saveLemonadeCPC.Value
        plr.PlayerGui.Game.Frame.Lemonade.Level.Text = "Level: "..saveLemonadeLevel.Value
        plr.PlayerGui.Game.Frame.Lemonade.WT.Text = "Wait Time: "..saveLemonadeWaitTime.Value.." Second"
    else
        local NumbersForSaving = {savevalue.Value, saves.saveLemonade.Value, saves.saveLemonadeLevel.Value, saves.saveLemonadeCPC.Value, saves.saveLemonadeWaitTime.Value, saves.saveLemonadeUpgradeCost.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
    local uniquekey = 'id-'..plr.userId
    local Savetable = {plr.leaderstats.Cash.Value,plr.saves.saveLemonade.Value, plr.saves.saveLemonadeLevel.Value, plr.saves.saveLemonadeCPC.Value, plr.saves.saveLemonadeWaitTime.Value, plr.saves.saveLemonadeUpgradeCost.Value}
    DSService:SetAsync(uniquekey, Savetable)
end)

Please don't downvote this as I tried to supply enough information as I could

0
Solved it! dotProgram 0 — 8y

Answer this question