Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

script.ChildAdded not firing

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?

1 answer

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)

1 comment

0

This did not fix the error. Nothing is being printed (still).

This discussion is preserved as it was. New answers, comments, and votes are closed.