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

How to prevent my datastore from giving nil instead it should save data?

Asked by 7 years ago

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.

01local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
02game.Players.PlayerAdded:connect(function(plr)
03   -- Define variables
04   print('waiting until tycoonscript ready')
05   wait(6)
06   print('Starting')
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
11    --leaderstats.Name = 'leaderstats'
12    --savevalue.Parent = leaderstats
13    --savevalue.Name = 'Cash'
14 
15    -- GetAsync
View all 39 lines...

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

0
GetSaved is the table, so GetSaved[1] would be the value. UgOsMiLy 1074 — 7y
0
Thanks for this i managed to fix it now. I didn't understand where the value would be I thought it was in GetSaved.Value Timmerman73 85 — 7y

Answer this question