Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ChildAdded event not firing (reask)

Asked by
TomsGames 225 Moderation Voter
10 years ago

Here is the whole script:

lp = game.Players.LocalPlayer

function onPlayerEntered(newPlayer)
        local stats = Instance.new("IntValue", newPlayer)
        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

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?

Posted previously but got no working answer. https://scriptinghelpers.org/questions/440/scriptchildadded-not-firing

1 answer

Log in to vote
0
Answered by 10 years ago

It is because on lines 31 and 24 you do not have ('s or )'s around :IsA().

Read more about the "IsA()" Instance here

0
Slightly patronising, but thanks, I forgot to put the ()'s. It still doesn't even print anything! TomsGames 225 — 10y
0
Is there any output at all? AmericanStripes 610 — 10y
1
Oh dear, slightly embarassing. Forgot it was running on a server script. I only checked player output, never server output! TomsGames 225 — 10y
Ad

Answer this question