Here is the whole script:
lp = game.Players.LocalPlayer function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local HighScore = Instance.new("IntValue") HighScore.Name = "HighScore" HighScore.Value = 0 local Score = Instance.new("IntValue") Score.Name = "Points" Score.Value = 0 HighScore.Parent = stats Score.Parent = stats stats.Parent = newPlayer end game.Players.ChildAdded:connect(onPlayerEntered) script.ChildAdded:connect(function (Obj) print("Leaderboard script has a child added.") if Obj:IsA "IntValue" and rawequal(Obj.Name, "HighScore") then if lp then local ls = lp:findFirstChild("leaderstats") hs = ls:findFirstChild("HighScore") hs.Value = Obj.Value Obj:destroy() end elseif Obj:IsA "IntValue" and rawequal(Obj.Name, "Score") then if lp then local ls = lp:findFirstChild("leaderstats") sc = ls:FindFirstChild("Points") sc.Value = sc.Value + Obj.Value Obj:destroy() end end end)
It runs, adds the leaderboard. However, when an object is added it does not fire and print "Leaderboard script has a child added."
What is wrong?
local lp = game.Players.LocalPlayer game.Players.ChildAdded:connect(function(p) local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local HighScore = Instance.new("IntValue", stats) HighScore.Name = "HighScore" HighScore.Value = 0 local Score = Instance.new("IntValue", stats) Score.Name = "Points" Score.Value = 0 end) script.ChildAdded:connect(function(Obj) print("Leaderboard script has a child added.") if lp then if Obj:IsA("IntValue") and Obj.Name == "HighScore" then local ls = lp:FindFirstChild("leaderstats") hs = ls:FindFirstChild("HighScore") hs.Value = Obj.Value Obj:Destroy() elseif Obj:IsA("IntValue") and Obj.Name == "Score" then local ls = lp:FindFirstChild("leaderstats") sc = ls:FindFirstChild("Points") sc.Value = sc.Value + Obj.Value Obj:Destroy() end end end)