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

Add up leaderboard values into total?

Asked by
Cuvette 246 Moderation Voter
8 years ago

Just a quick one, is there a way to add up the total values of every players cash for example on a leader board?

3 answers

Log in to vote
2
Answered by
Cuvette 246 Moderation Voter
8 years ago
Edited 8 years ago

Solved it from DaCrazy's answer.

while true do
    total = 0
    players = game.Players:GetChildren()
    for i,players in pairs(players) do
        total = total + players.leaderstats.Status.Value
    end
    print(total)
    wait(1)
end

Works fine

And just for clearance, i'm not some beginner. This was such a basic question, but I've had a long day.

1
Glad I helped. DaCrazyDev 444 — 8y
Ad
Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

I don't want to give this out completely, because you wouldn't learn, and that isn't the purpose of this website, so, I hope this isn't doing that. You edit it around.

local total

for _,leaderstat in pairs(player.leaderstats:GetChildren()) do
    total = total + leaderstat.Value
end

print(total)

-- You can do whatever else you want with the total here.


0
Thanks, that will do fine. I'm much more adept than that question makes me sound, just a brain dead moment. Cuvette 246 — 8y
1
Np, didn't want to give it out completely, because we're not really supposed to, but I decided to just do it this time, because I was at your point before and I hated it. DaCrazyDev 444 — 8y
2
You're still fairly new to answering questions, Crazy, so here is another tip: Always make sure to explain your answer - not explaining it is basically just being lazy and often doesn't help the person in need that much. TheDeadlyPanther 2460 — 8y
0
You're still fairly new to answering questions, Crazy, so here is another tip: Always make sure to explain your answer - not explaining it is basically just being lazy and often doesn't help the person in need that much. TheDeadlyPanther 2460 — 8y
Log in to vote
1
Answered by 8 years ago

Although Scripting Helpers was made for help, and not requests, ill be nice this one time. Dont expect others being nice, though. It does get quite annoying when people request.

Anyways, all you would have to do is something like this:

local allcash = Instance.new("NumberValue", game.ReplicatedStorage)
allcash.Name = "CashForEveryPlayer"
allcash.Value = 0

for i,v in pairs(game.Players:GetPlayers()) do
    allcash.Value = allcash.Value + v.leaderboard.Cash.Value
end
0
I wasn't requesting for a script or anything in the first place, just a concept. I really should have worked it out on my own It's just too late at night for me (: but thanks anyway. Cuvette 246 — 8y

Answer this question