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
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.
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?