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

How to add more than 1 stat on leaderstats?

Asked by 4 years ago
Edited 4 years ago

Hi so I am new to this Scripting stuff and I don't know how to add another stat along with one on my leaderstats. Here is what I tried to do,

> function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local score = Instance.new("IntValue")

    score.Name = "Sips"
    score.Value = 0

    score.Parent = stats    
    stats.Parent = newPlayer
end
function onPlayerEntered(newPlayer)
    wait(.5)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local score = Instance.new("IntValue")

    score.Name = "Cash"
    score.Value = 0

    score.Parent = stats    
    stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)

0
Please format your code. It's hard to read so we can't help you. In order to properly format the code, press the little blue button on the top when editing/writing your code. Sensei_Developer 298 — 4y
0
I fixed it can you help now? JuzeyPlayz -83 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The thing that you did is forget to name the variables differently. If you do that, you will only have 1 stat on leaderstats. This is something that would work:

local sips = Instance.new("IntValue")

score.Name = "Sips"
score.Value = 0

score.Parent = stats   
stats.Parent = newPlayer


local cash = Instance.new("IntValue")

score.Name = "Cash"
score.Value = 0

score.Parent = stats   
stats.Parent = newPlayer

0
Make sure to close your leaderboard with an end. JesseSong 3916 — 4y
0
I know, I was just making the part that the person made an error with. youtubemasterWOW 2741 — 4y
0
Do I add an end at end of live 7 or both?? But thank you very much this will help me with my game. JuzeyPlayz -83 — 4y
0
Yes, you should add an end at line 8. youtubemasterWOW 2741 — 4y
Ad
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

What you have to do is the following code:

game.Players.PlayerAdded:connect(function(p)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    stats.Parent = p

    local money = Instance.new("IntValue")
    money.Name = "Money" -- Change "Money" to anything you want to name it like "Cash"
    money.Value = 50 -- Change the value to how many you want when the player joins the game
    money.Parent = stats


    local Whatever = Instance.new("IntValue")
    Whatever.Name = "Whatever" -- Change "Whatever" to anything you want to name it like "Cash"
    Whatever.Value = 50 -- Change the value to how many you want when the player joins the game
    Whatever.Parent = stats

end)

0
If my code helped you please accept my answer. JesseSong 3916 — 4y

Answer this question