How to prevent my datastore script from giving an Error?
Asked by
7 years ago Edited 7 years ago
I have a script that saves Money from Players so they keep it the next time they join but it gives an error and I dont know how to fix it. Here is my script:
01 | local DSService = game:GetService( 'DataStoreService' ):GetDataStore( 'Hamburger223232' ) |
02 | game.Players.PlayerAdded:connect( function (plr) |
04 | print ( 'waiting until tycoonscript ready' ) |
07 | local uniquekey = 'id-' ..plr.userId |
08 | local leaderstats = Instance.new( 'IntValue' , plr) |
09 | local Moneystorage = game.ServerStorage:FindFirstChild( 'PlayerMoney' ) |
10 | local PlayerMoney = Moneystorage:FindFirstChild(plr.Name) |
11 | local savevalue = PlayerMoney |
17 | local GetSaved = DSService:GetAsync(uniquekey) |
19 | savevalue.Value = GetSaved [ 1 ] |
21 | local NumbersForSaving = { savevalue.Value } |
22 | DSService:SetAsync(uniquekey, NumbersForSaving) |
26 | game.Players.PlayerRemoving:connect( function (plr) |
27 | local Moneystorage = game.ServerStorage:FindFirstChild( 'PlayerMoney' ) |
28 | local PlayerMoney = Moneystorage:FindFirstChild(plr.Name) |
29 | local savevalue = PlayerMoney |
30 | local uniquekey = 'id-' ..plr.userId |
31 | local Savetable = { savevalue.Value } |
32 | DSService:SetAsync(uniquekey, Savetable) |
When i test it with an alt in game this is what shows in the output.
ServerScriptService.Save Service :19: attempt to index local 'savevalue' (a number value)
If anybody could help that would be amazing
'