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

How come only "Wins" come up on the leaderboard and not all of the ones i created?

Asked by 7 years ago
print("Leaderboard loaded")

function onPlayerEntered(newPlayer)

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

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Value = 0

    local diamonds = Instance.new("IntValue")
    diamonds.Name = "Diamonds"
    diamonds.Value = 0

    local wins = Instance.new("IntValue")
    wins.Name = "Wins"
    wins.Value = 0

    local level = Instance.new("IntValue")
    level.Name = "Level"
    level.Value = 0

    local exp = Instance.new("IntValue")
    exp.Name = "Exp"
    exp.Value = 0

    coins.Parent = stats
    diamonds.Parent = stats
    wins.Parent = stats
    level.Parent = stats
    exp.Parent = stats

end

This is the script i created to make Exp, Level, Coins, Diamonds, and Wins. Though only wins come up when i play the game. Help?

1 answer

Log in to vote
0
Answered by
StoIid 364 Moderation Voter
7 years ago

I believe it is because you forgot to parent the actual leaderstats IntValue into the player that is joining, try this.

print("Leaderboard loaded")

function onPlayerEntered(newPlayer)

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

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

    local diamonds = Instance.new("IntValue", stats)
    diamonds.Name = "Diamonds"
    diamonds.Value = 0

    local wins = Instance.new("IntValue", stats)
    wins.Name = "Wins"
    wins.Value = 0

    local level = Instance.new("IntValue", stats)
    level.Name = "Level"
    level.Value = 0

    local exp = Instance.new("IntValue", stats)
    exp.Name = "Exp"
    exp.Value = 0

print("Leaderboard Fully loaded")
end

I also removed the bits of code you had at the bottom because doing what I did is more efficient.

When you put a , after a instance you are creating you are setting its parent.

Here is an example:

--x = Instance.new(InstanceName, Parent) 
x = Instance.new('Part', game.Lighting) -- This will create a part and instead of it being put in workspace, it will be placed in the lighting. 

This helps eliminate lines of code therefore reducing reading and also removing room for error in your code. You should stick to this method of setting parents for new script generated objects from now on.

Hope this helped!

0
Oh really? Alright then, i will start using your method, thanks for the help! Supergamerboy1995 129 — 7y
Ad

Answer this question