Getting a "attempt to index a nil value" error in my DataStore2?
Asked by
5 years ago Edited 5 years ago
The output tells me there's an error line 54 of my script, but I don't quite understand why?
01 | local DataStore 2 = require(game.ServerScriptService:WaitForChild( "DataModule" )) |
02 | local MainKey = "MainKey" |
03 | DataStore 2. Combine(MainKey, "Stats" , "Achievment" ) |
07 | local function SetDataTable() |
23 | game.Players.PlayerAdded:Connect( function (plr) |
24 | local UserData = DataStore 2 (MainKey,plr) |
27 | local leaderstats = Instance.new( "Folder" ) |
28 | leaderstats.Name = "leaderstats" |
30 | local kills = Instance.new( "IntValue" ) |
33 | local deaths = Instance.new( "IntValue" ) |
34 | deaths.Name = "Deaths" |
36 | local xp = Instance.new( "IntValue" ) |
39 | local xpn = Instance.new( "IntValue" ) |
42 | local level = Instance.new( "IntValue" ) |
45 | local coins = Instance.new( "IntValue" ) |
48 | local gems = Instance.new( "IntValue" ) |
51 | local StatsData = DataStore 2 ( "Stats" ,plr) |
53 | local function UpdateStats(updatedValue) |
54 | kills.Value = StatsData:Get(updatedValue).kills |
55 | deaths.Value = StatsData:Get(updatedValue).deaths |
56 | xp.Value = StatsData:Get(updatedValue).xp |
57 | xpn.Value = StatsData:Get(updatedValue).xpn |
58 | level.Value = StatsData:Get(updatedValue).level |
59 | coins.Value = StatsData:Get(updatedValue).coins |
60 | gems.Value = StatsData:Get(updatedValue).gems |
65 | UpdateStats(UserData.Stats) |
67 | StatsData:OnUpdate(UpdateStats) |
70 | leaderstats.Parent = plr |
71 | kills.Parent = leaderstats |
72 | deaths.Parent = leaderstats |
73 | xp.Parent = leaderstats |
74 | level.Parent = leaderstats |
75 | coins.Parent = leaderstats |
76 | gems.Parent = leaderstats |
82 | local KeyData = DataStore 2 (MainKey) |
86 | local function LevelUp() |