game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new("IntValue", game.Workspace) stats.Name = "leaderstats" local points = Instance.new("IntValue", stats) points.Name = "Points" points.Value = 0 plr.CharacterAdded:connect(function(char) (char:WaitForChild("Humanoid")).Died:connect(function() plr.leaderstats.points.Value = plr.leaderstats.points.Value - 1 end) end) end)
why does line 9 of this leaderboard script throw an error once humanoid dies???
game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new("IntValue", plr) stats.Name = "leaderstats" local points = Instance.new("IntValue", stats) points.Name = "Points" points.Value = 0 plr.CharacterAdded:connect(function(char) (char:WaitForChild("Humanoid")).Died:connect(function() points.Value = points.Value - 1 end) end) end)
Look back up at line 5, where you name the points(in the leaderstats model) as "Points". When referencing this, you have to use that name. In line 9, you look under player using plr, which is fine because that is a variable, then leaderstats, which is fine because the name is "leaderstats", but then you look for an object called "points", when the childs you are really looking for is "Points".
Long story short, capitalize points when you use it because the name you set it as is capitalized as well, so the script should be
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 1