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)
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 ...
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'