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

What is wrong, here?

Asked by
Kyokamii 133
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I know the 'Tokens' stats work.

But the 'Coins' stats don't!

Output:

Coins is not a valid member of IntValue

Here is the script:

function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local captures = Instance.new("IntValue")
    captures.Name = "Tokens"
    captures.Value = 0
    captures.Parent = stats
    stats.Parent = newPlayer


    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    local captures = Instance.new("IntValue")
    captures.Name = "Coins"
    captures.Value = 0
    captures.Parent = stats
    stats.Parent = newPlayer

end

game.Players.ChildAdded:connect(onPlayerEntered)

2 answers

Log in to vote
6
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

After creating stats, you then go and create it again (line 11 and line 12).

If you check the hierarchy, you should see two leaderstats entries; one will have Tokens and the other will have Coins in it. I imagine only one will actually display in the leaderboard.


Don't redefine stats - use the same one for both.


For clarity, you should really organize your code more like this. The second parameter to Instance.new is very nice!

...

    local stats = Instance.new("IntValue", newPlayer)
    stats.Name = "leaderstats"

    local captures = Instance.new("IntValue", stats)
    captures.Name = "Tokens"
    captures.Value = 0

    local captures = Instance.new("IntValue", stats)
    captures.Name = "Coins"
    captures.Value = 0

...
0
Thx! It fixed right up! Kyokamii 133 — 9y
Ad
Log in to vote
1
Answered by
Muoshuu 580 Moderation Voter
9 years ago

Try removing

local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

from line 11-12

and changing 'captures' on line 13-16 to another name, like 'captures2' or 'dogs'

The reason why this is breaking it is because you are looking for 'Coins' in the very first 'leaderstats' object, but the very first 'leaderstats' object only contains 'Tokens'

Answer this question