I have a question about DataStores? Its changing the values when you rejoin?
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
01 | if (saves.saveLemonade.Value = = true ) then |
02 | plr.PlayerGui.Game.Frame.Lemonade.Buy.Visible = false |
03 | plr.PlayerGui.Game.Frame.Lemonade.MakeCash.Visible = true |
04 | plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Visible = true |
05 | plr.PlayerGui.Game.Frame.Lemonade.MakeCash.MPC.Value = saveLemonadeCPC.Value |
06 | plr.PlayerGui.Game.Frame.Lemonade.MakeCash.WaitTime.Value = saveLemonadeWaitTime.Value |
07 | plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Level.Value = saveLemonadeLevel.Value |
08 | plr.PlayerGui.Game.Frame.Lemonade.Upgrade.UpgradeCost.Value = saveLemonadeUpgradeCost.Value |
09 | plr.PlayerGui.Game.Frame.Lemonade.CPC.Visible = true |
10 | plr.PlayerGui.Game.Frame.Lemonade.Level.Visible = true |
11 | plr.PlayerGui.Game.Frame.Lemonade.WT.Visible = true |
12 | plr.PlayerGui.Game.Frame.Lemonade.CPC.Text = "Cash Per Click: " ..saveLemonadeCPC.Value |
13 | plr.PlayerGui.Game.Frame.Lemonade.Level.Text = "Level: " ..saveLemonadeLevel.Value |
14 | plr.PlayerGui.Game.Frame.Lemonade.WT.Text = "Wait Time: " ..saveLemonadeWaitTime.Value.. " Second" |
Heres the full data store code.
01 | local DSService = game:GetService( 'DataStoreService' ):GetDataStore( 'AdVentureCapOfficialDataStore' ) |
02 | game.Players.PlayerAdded:connect( function (plr) |
03 | local uniquekey = 'id-' ..plr.userId |
04 | local leaderstats = Instance.new( 'IntValue' , plr) |
05 | leaderstats.Name = 'leaderstats' |
06 | local saves = Instance.new( 'IntValue' , plr) |
08 | local savevalue = Instance.new( 'NumberValue' ) |
09 | savevalue.Parent = leaderstats |
10 | savevalue.Name = 'Cash' |
12 | local saveLemonade = Instance.new( 'BoolValue' ) |
13 | saveLemonade.Name = "saveLemonade" |
14 | saveLemonade.Parent = saves |
15 | local saveLemonadeLevel = Instance.new( 'IntValue' ) |
16 | saveLemonadeLevel.Name = "saveLemonadeLevel" |
17 | saveLemonadeLevel.Parent = saves |
18 | local saveLemonadeCPC = Instance.new( 'NumberValue' ) |
19 | saveLemonadeCPC.Name = "saveLemonadeCPC" |
20 | saveLemonadeCPC.Parent = saves |
21 | local saveLemonadeWaitTime = Instance.new( 'NumberValue' ) |
22 | saveLemonadeWaitTime.Name = "saveLemonadeWaitTime" |
23 | saveLemonadeWaitTime.Parent = saves |
24 | local saveLemonadeUpgradeCost = Instance.new( 'NumberValue' ) |
25 | saveLemonadeUpgradeCost.Name = "saveLemonadeUpgradeCost" |
26 | saveLemonadeUpgradeCost.Parent = saves |
27 | local saveNewsPaper = Instance.new( 'BoolValue' ) |
28 | saveNewsPaper.Name = "saveNewsPaper" |
29 | saveNewsPaper.Parent = saves |
30 | local saveNewsPaperLevel = Instance.new( 'IntValue' ) |
31 | saveNewsPaperLevel.Name = "saveNewsPaperLevel" |
32 | saveNewsPaperLevel.Parent = saves |
33 | local saveNewsPaperCPC = Instance.new( 'NumberValue' ) |
34 | saveNewsPaperCPC.Name = "saveNewsPaperCPC" |
35 | saveNewsPaperCPC.Parent = saves |
36 | local saveNewsPaperWaitTime = Instance.new( 'NumberValue' ) |
37 | saveNewsPaperWaitTime.Name = "saveNewsPaperWaitTime" |
38 | saveNewsPaperWaitTime.Parent = saves |
39 | local saveNewsPaperUpgradeCost = Instance.new( 'NumberValue' ) |
40 | saveNewsPaperUpgradeCost.Name = "saveNewsPaperUpgradeCost" |
41 | saveNewsPaperUpgradeCost.Parent = saves |
42 | local saveCarWash = Instance.new( 'BoolValue' ) |
43 | saveCarWash.Name = "saveCarWash" |
44 | saveCarWash.Parent = saves |
45 | local saveCarWashLevel = Instance.new( 'IntValue' ) |
46 | saveCarWashLevel.Name = "saveCarWashLevel" |
47 | saveCarWashLevel.Parent = saves |
48 | local saveCarWashCPC = Instance.new( 'NumberValue' ) |
49 | saveCarWashCPC.Name = "saveCarWashCPC" |
50 | saveCarWashCPC.Parent = saves |
51 | local saveCarWashWaitTime = Instance.new( 'NumberValue' ) |
52 | saveCarWashWaitTime.Name = "saveCarWashWaitTime" |
53 | saveCarWashWaitTime.Parent = saves |
54 | local saveCarWashUpgradeCost = Instance.new( 'NumberValue' ) |
55 | saveCarWashUpgradeCost.Name = "saveCarWashUpgradeCost" |
56 | saveCarWashUpgradeCost.Parent = saves |
57 | local GetSaved = DSService:GetAsync(uniquekey) |
59 | savevalue.Value = GetSaved [ 1 ] |
60 | saveLemonade.Value = GetSaved [ 1 ] |
61 | saveLemonadeLevel.Value = GetSaved [ 1 ] |
62 | saveLemonadeCPC.Value = GetSaved [ 1 ] |
63 | saveLemonadeWaitTime.Value = GetSaved [ 1 ] |
64 | saveLemonadeUpgradeCost.Value = GetSaved [ 1 ] |
65 | plr.PlayerGui.Game.Frame.CASH.Text = plr.leaderstats.Cash.Value.. "$" |
66 | if (saves.saveLemonade.Value = = true ) then |
67 | plr.PlayerGui.Game.Frame.Lemonade.Buy.Visible = false |
68 | plr.PlayerGui.Game.Frame.Lemonade.MakeCash.Visible = true |
69 | plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Visible = true |
70 | plr.PlayerGui.Game.Frame.Lemonade.MakeCash.MPC.Value = saveLemonadeCPC.Value |
71 | plr.PlayerGui.Game.Frame.Lemonade.MakeCash.WaitTime.Value = saveLemonadeWaitTime.Value |
72 | plr.PlayerGui.Game.Frame.Lemonade.Upgrade.Level.Value = saveLemonadeLevel.Value |
73 | plr.PlayerGui.Game.Frame.Lemonade.Upgrade.UpgradeCost.Value = saveLemonadeUpgradeCost.Value |
74 | plr.PlayerGui.Game.Frame.Lemonade.CPC.Visible = true |
75 | plr.PlayerGui.Game.Frame.Lemonade.Level.Visible = true |
76 | plr.PlayerGui.Game.Frame.Lemonade.WT.Visible = true |
77 | plr.PlayerGui.Game.Frame.Lemonade.CPC.Text = "Cash Per Click: " ..saveLemonadeCPC.Value |
78 | plr.PlayerGui.Game.Frame.Lemonade.Level.Text = "Level: " ..saveLemonadeLevel.Value |
79 | plr.PlayerGui.Game.Frame.Lemonade.WT.Text = "Wait Time: " ..saveLemonadeWaitTime.Value.. " Second" |
81 | local NumbersForSaving = { savevalue.Value, saves.saveLemonade.Value, saves.saveLemonadeLevel.Value, saves.saveLemonadeCPC.Value, saves.saveLemonadeWaitTime.Value, saves.saveLemonadeUpgradeCost.Value } |
82 | DSService:SetAsync(uniquekey, NumbersForSaving) |
87 | game.Players.PlayerRemoving:connect( function (plr) |
88 | local uniquekey = 'id-' ..plr.userId |
89 | 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 } |
90 | DSService:SetAsync(uniquekey, Savetable) |
Please don't downvote this as I tried to supply enough information as I could