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

Why am i getting a nil error for "Cash" in this Data Store script?

Asked by 4 years ago
01local DataStoreService = game:GetService("DataStoreService")
02  local myDataStore = DataStoreService:GetDataStore("myDataStore")
03   
04  game.Players.PlayerAdded:Connect(function(player)
05   
06  local leaderstats = Instance.new("Folder")
07  leaderstats.Name = "leaderstats"
08  leaderstats.Parent = player
09   
10  local Cash = Instance.new("IntValue")
11  Cash.Name = "Cash"
12  Cash.Parent = leaderstats
13   
14  local Wins = Instance.new("IntValue")
15  Wins.Name = "Wins"
View all 51 lines...

when i try to save, the output gives this error - ServerScriptService.Save:28: attempt to index nil with 'Cash' Im not sure how to fix it, any help would be great.

1
Key's are unique identifiers, any minor difference, even capitalization, can make them worlds apart. On line 18, you declare a Key with a capital 'P' in 'Player', whereas the Key you save to is 'player'. There is no data allocated under that key, therefore you recieve nil. Ziffixture 6913 — 4y

Answer this question