To delete data from data stores, you need to use the DataStore:RemoveAsync()
method.
First, go to your free-to-use scripts. You can easily find where data stores are updated: hold CTRL
+SHIFT
+F
and search for UpdateAsync
and SetAsync
. Go to these positions in the script.
At these points, you might see code in this kind of format:
--ONE of these FOUR
DataStore:SetAsync(..., ...)
pcall(DataStore.SetAsync, DataStore, ..., ...)
DataStore:UpdateAsync(..., function(...)
--blah blah, this bit doesn't matter
end)
pcall(DataStore.UpdateAsync, DataStore, ..., function(...)
--blah blah, this bit still doesn't matter
end)
Now, you don’t need to understand what this code does. You need to retrieve a value from it.
In the code, I need you to get the value which is marked as key
in my code snippet below:
--ignore if it's SetAsync or UpdateAsync, that does not matter.
--The placement of 'key' will be the same in both cases.
pcall(DataStore.UpdateAsync, DataStore, key, function(...)
end)
--or
DataStore:UpdateAsync(key, function(...)
end)
Now, this value market key
. Why’d I ask you to get it? Well, basically, when we save player’s data, we need to provide a special thing called a key. This is basically what we use to access the player’s data.
When you get this key, it could look something like this:
"Key_"..player.UserId
"leadervalue-"..player.UserId
--or literally just
player.UserId
If you see any dots before or after the player’s UserId part, you need those. Those are what we call prefixes or suffixes to the key. If it literally just says player.UserId
or just has a .UserId
part to it, that makes the next part a whole lot easier.
Now, go to the top of that script, or use CTRL+SHIFT+F
again to go back to search mode. Type in :GetDataStore
. Go to where this position is in the script, and get what’s written in the speech marks. That’s the name of the data store.
Now, type this in the command bar:
--IGNORE THESE BITS WHICH ARE INDICATED BY -- and in italics
--they are comments and do not matter!
--what you need is below.
--suffix is the little string bit next to the key you had before.
local key = "Key-"..UserId --UserId is the UserId of the user who has right to erasure.
--Note if the dots were before the UserId part in the script, you must put it before here.
--If it was after, it needs to be after the UserId part here.
--in this command, "name" is the name of the data store which you got from the script earlier.
game:GetService("DataStoreService"):GetDataStore(name):RemoveAsync(key)
If it all worked out correctly, the player’s data will now be gone from the data store. I hope this helped explain it really simply, and if you need further help please let me know. This should let you remove data without having to disable the data stores.
Disclaimer
I am not sure if this is all you need to do to remove the required data by law. For that reason, I will not accept responsibility for insufficient/incompliant removal of data by the use of this code. You acknowledge that and accept by using my code. (I DONT WANNA GET SUED!!)