Ad
Log in to vote
0

Add up leaderboard values into total?

Asked by
Cuvette 222
4 months 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?

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

3 answers

Log in to vote
1
Answered by
Function 140
4 months 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 222 — 4mo
Ad
Log in to vote
1
Answered by
Cuvette 222
4 months ago
Edited 4 months 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 33 — 4mo
Log in to vote
0
Answered by 4 months ago
Edited 4 months 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 222 — 4mo
0
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 33 — 4mo
1
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 1813 — 4mo
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 1813 — 4mo

Answer this question



Ad