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

How can I set everyone's leaderstats amount to 0? [closed]

Asked by 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

Hello,

I am working on a game, and I had some friends test it. There's a kills leaderstat and I want to wipe everyone's program (set everyone to 0). How can I do this?

Thank you, KreativleV2

0
I don't understand how this isn't as simple as setting every value inside of the leaderstats folder to 0? I mean, any Instance named leaderstats technically works, but this is logically speaking. DeceptiveCaster 3761 — 4y
0
I just don't have them in a game, is there a way to do this? And if so, could you give me a simple explanation on how to do it? KreativleV2 0 — 4y
0
Iterate through each Player within the "Players" Service. Locate their "leaderstats" folder and set the respective stat to zero. Ziffixture 6913 — 4y
0
The player isn't in the game though, so how do I get their player? KreativleV2 0 — 4y
View all comments (2 more)
0
What do you mean by, "isn't in the game"? Ziffixture 6913 — 4y
0
@Feahren he means that the data is saved into data store so he wants to remove the save. No you can't, only if you use RemoveAsync() - You would need to know the key of the save. Or you can just change name of the data store (Which will wipe ALL the data) imKirda 4491 — 4y

Closed as Non-Descriptive by DeceptiveCaster

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Edit: Isn't in game means you have data store and you want to wipe the saved data? No you can't only if you use RemoveAsync() - You would need to know the key or you can just change name of the data store (Bad way).

I assume it's in leaderstats folder which is inside of the player? You can use Players:GetPlayers() function which returns table of all players that are in the game. Simply get the Players service and fire the function it:

local Players = game:GetService("Players")

local AllPlayers = Players:GetPlayers()

Now you would have to run loop for the table, pairs loop to be exact. It loops through table and returns 2 variables, it's index in the table (In this case number position of the Player in the table) and the value assigned to it (In this case Player Instance):

for Index, Player in pairs(AllPlayers) do
    print(Index, Player)
end

Now this is example to fully show what it does, if for example in game there were 3 players, Bob, Mariah and WideSeal, this would be the output:

[1] Bob
[2] Mariah
[3] WideSeal

So as i said before, i assume every player has leaderstats folder and kills value in it so in your case you would just change the value to 0:

for Index, Player in pairs(AllPlayers) do
    local Leaderstats = Player.leaderstats -- the leaderstats folder
    local kills = leaderstats.kills -- the kills value

    kills.Value = 0
end

And that's it. Don't accept if it didn't help.

Ad