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

How to reset a value in leaderstats?

Asked by 9 years ago

How would I reset one value on the leaderboard?

Thanks!

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Assuming you want to reset the stat for ALL players then what you have to do is..

1) Make a variable that contains the name of the leaderstat you wish to reset.

2) Use a generic for loop to iterate through a table full of all the Players in the server.

3) Set the leaderstat, stored in 'leaderstats', which is in the Player, to 0.

local stat = "Kills" --Name of stat to reset
local players = game.Players:GetPlayers() --All the players

for i,v in pairs(players) do --iterate through all players
    if v.leaderstats then
        local lstat = v.leaderstats:FindFirstChild(stat) --get the stat
        if lstat then --check if stat exists
            lstat.Value = 0 --Reset it
        end
    end
end
Ad

Answer this question