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

What is wrong, here?

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

✓ Accepted answer

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

...

1 comment

0

Thx! It fixed right up!

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'

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