Erasing Data in a Data Store

Hi, I own a game with a global leaderboard. As you know, exploiters easily climb up it. I’m trying to find a way to remove the exploiters data in the data store. I barely use data stores so I apologize if I ask a few more questions. Here is what I’m thinking of using:

local Exploiters = {"stickymirro511","player"} ---The people who exploited.

	for i, v in pairs(Exploiters) do
		---Erase the data in the data store.

Please note, this could mean the exploiters never join back. I’m wondering if I could delete their data without having them to join. Thanks.

1 Like

You can use the datastore editor plugin


1 Like

Thanks, but I can’t afford it at the moment, I’m wondering if it’s possible to do it in a script.

I have a temporary solution, you could make the leaderboard have a blacklist, so anyone placed on the list will not be placed onto the leaderboard.

Thanks, that would be a good solution if I were able to script that. My scripting skills aren’t the best.

Yes, you can.

You can just override his data. You need his userId for that probably, it depends on what your key for your DataStore is (what you use when you do DS:GetAsync()).
If your DataStore has names as keys, then that’s even easier but not that secure, as you can change your name on Roblox.

You can get an UserId from a name though:

An example would be:

local players = game:GetService("Players")
local Exploiters = {"stickymirro511","player"}
local DataStoreService = game:GetService("DataStoreService")
local pointDataStore = DataStoreService:GetDataStore("PointDataStore")

for i,v in next, Exploiters do
       local exploiterUserId = players:GetUserIdFromNameAsync(v)
       --Now you can just set his points or whatever to 0
       pointDataStore:SetAsync(exploiterUserId, 0)

Good to know: You could also get the player (the exploiter) by his userId with the players:GetPlayerByUserId() function.

1 Like

Thanks, do I change this to my data store key?

pointDataStore:SetAsync(exploiterUserId, 0)

What do you mean?
You use your dataStore key.
If you set the name as key, then you also do

pointDataStore:SetAsync(exploiterName, 0)

Like what do you do when the player leaves/when you want to save his data?

pointDataStore:SetAsync(playerWhoIsLeaving.UserId, playerWhoIsLeaving.leaderstats.Points.Value)

Something like that, don’t you? That’s what I do, I use the UserId as key usually.

Oh thanks, does

  pointDataStore:SetAsync(exploiterUserId, 0)

erase all data the exploiter has? Sorry, I barely use data stores.

1 Like

Do you only have one DataStore?
If so, then yeah, if it’s something like Cash/Points, then his Cash/Points will be 0 the next time you get his Async.

Thanks, I have one last question. Should I make it a local script and put it in serverscriptservice?

1 Like

You don’t put Local Scripts into ServerScriptService.
This should be a ServerScript. I’m pretty sure DataStoreService doesn’t work on Local Scripts.

You can put it into ServerScriptService as a ServerScript.

1 Like

You guys do realise there is a function called RemoveAsync?

Yes, I have no idea how to use it.


Wouldn’t that erase everyone’s data?

If you have everyone saved as one key then yes, but if everyone is a different key then all you need is that key

I have one key for everyone. Is there a way to make it so only one person’s data get erased?

DataStore:UpdateAsync("Key", function(previousData) 
    -- If it is JSONEncodeded, then decode it
    previousData.SomePlayersKey = nil
    return playerData
1 Like