Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

6 comments

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.

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?

0

Iterate through each Player within the "Players" Service. Locate their "leaderstats" folder and set the respective stat to zero.

0

The player isn't in the game though, so how do I get their player?

0

What do you mean by, "isn't in the game"?

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)

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.