01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local myDataStore = DataStoreService:GetDataStore( "myDataStore" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
06 | local leaderstats = Instance.new( "Folder" ) |
07 | leaderstats.Name = "leaderstats" |
08 | leaderstats.Parent = player |
10 | local Cash = Instance.new( "IntValue" ) |
12 | Cash.Parent = leaderstats |
14 | local Wins = Instance.new( "IntValue" ) |
16 | Wins.Parent = leaderstats |
18 | local playerUserId = "Player_" ..player.UserId |
23 | local success, errormessage = pcall ( function () |
24 | data = myDataStore:GetAsync(playerUserId) |
28 | Cash.Value = data.Cash |
29 | Wins.Value = data.Wins |
34 | game.Players.PlayerRemoving:Connect( function (player) |
35 | local playerUserId = "player_" ..player.UserId |
38 | Cash = player.leaderstats.Cash.Value; |
39 | Wins = player.leaderstats.Wins.Value; |
42 | local success, errormessage = pcall ( function () |
43 | myDataStore:SetAsync(playerUserId, data) |
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.