How to prevent my datastore from giving nil instead it should save data?
I have a datastore script that saves a players money for the next time they join their money is stored in ServerStorage.PlayerMoney.Playername This is the script i currently have
The script is in ServerScriptService and is a server side 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 Moneystorage = game.ServerStorage:FindFirstChild( 'PlayerMoney' ) |
09 | local PlayerMoney = Moneystorage:FindFirstChild(plr.Name) |
10 | local savevalue = PlayerMoney.Value |
16 | local GetSaved = DSService:GetAsync(uniquekey) |
21 | savevalue = GetSaved [ 1 ] |
23 | local NumbersForSaving = { savevalue.Value } |
25 | DSService:SetAsync(uniquekey, NumbersForSaving) |
30 | game.Players.PlayerRemoving:connect( function (plr) |
31 | local Moneystorage = game.ServerStorage:FindFirstChild( 'PlayerMoney' ) |
32 | local PlayerMoney = Moneystorage:FindFirstChild(plr.Name) |
33 | local savevalue = PlayerMoney |
34 | local uniquekey = 'id-' ..plr.userId |
35 | local Savetable = { savevalue.Value } |
37 | DSService:SetAsync(uniquekey, Savetable) |
This is the output in game.
https://imgur.com/a/sPeBJ
I set the money of my alt to 1000 then i let it rejoin but it still shows nil.
How to make it output the money thats saved and give it to the player