My datasave doesn't save at all? [closed]
Hello, a few weeks ago I watched a tutorial on DataSaving from AlvinBlox, mainly because I was a little confuzzled with it. I'm trying to save a number value (I believe it's called integers) via a location in the player's gui. Here's my code:
01 | local DSService = game:GetService( 'DataStoreService' ):GetDataStore( 'XIPHER_921838582315538283812581238529158283' ) |
02 | game.Players.PlayerAdded:connect( function (plr) |
04 | local uniquekey = 'id-' ..plr.userId |
05 | local savevalue = plr.PlayerGui:WaitForChild( "Cash" ).CashFrame.MoneyHolder.Money.MoneyHolder |
07 | local GetSaved = DSService:GetAsync(uniquekey) |
09 | savevalue.Value = GetSaved [ 1 ] |
11 | local NumbersForSaving = { savevalue.Value } |
12 | DSService:SetAsync(uniquekey, NumbersForSaving) |
16 | game.Players.PlayerRemoving:connect( function (plr) |
17 | local uniquekey = 'id-' ..plr.userId |
18 | local Savetable = { plr.PlayerGui:WaitForChild( "Cash" ).CashFrame.MoneyHolder.Money.MoneyHolder.Value } |
19 | DSService:SetAsync(uniquekey, Savetable) |
As you can see, I'm trying to save a value in a place in the player's gui. The script is a normal script, not a localscript and is in ServerScriptStorage. If anyone can help me whether if it should be in a different location, if it should be a localscript instead, or generally help me. Super appreciated!
P.S
I tried earlier with studio and it does load a integer I saved a few minutes ago when I used leaderstats instead and realized that it does load the saved data but it doesn't save the data. For example, if the player had saved 10k coins from earlier, and it correctly saved. The player joins back and earns another 10k coins and then leaves. It will only load in 10k coins because it doesn't save the coins and will only load the last data that WAS saved.