How should I remove a player's data from datastores correctly?

Hello, I would like to remove some data of UserIds roblox has asked me to in a Right to Erasure message. These users are all deleted so I do not have their usernames either. I only have one game that saves player’s data, my issue is that I don’t know if what I’ve done worked so far or not.

So far I’ve tried following what it says on the data store and global datastore pages as well as what people have posted around the devforums. In studio’s command bar I’ve pasted the data store removal script I’ve edited, here is some context:

local success, nickname = pcall(function()
return nicknameStore:RemoveAsync("Player_I put their UserId here")
end)

After running the script I looked in the output tab to see result:
image

I’m unsure if this means it has worked or not, I’m also unsure how to handle removal of global data correctly as well. I’ve already emailed roblox regarding this so I’m waiting for a response to see what support says too.

6 Likes

RemoveAsync returns the value associated with the passed key and returns it. If RemoveAsync is returning nil, then there is no data saved to the key you passed and you are fine. Internally, the key will not exist under your DataStore. Just make sure you do a double check on all methods of data saving in your game and use RemoveAsync in the same manner if present.

2 Likes

Roblox replied to my email basically telling me about the consequences and other information they already informed me about.

I’m not really much of a scripter myself so I’m still unsure how to go about handling this other than taking the game effected down completely which I might do.

3 Likes

Do you know the name for all the datastores that may include their information?

My game has a datastore for the leaderboards stats and a global leaderboard to tell which player has the highest stat. It’s basically a simulator type game.

I followed scripting tutorials to create the datastores. If worse comes to worse I can take down the game, no one really plays it at all.

In the code you provided, you’re simply saying if success then print string + the nonexistant error.

pcall is local success,error (I generally do suc,err to avoid function conflicts)
You’re going to want to do:

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("NAME")
local suc,err = pcall(function()
   DS:RemoveAsync("KEY")
end)
if err then
   console.warn(err)
end

Updated Version

In this updated version, the returned value of the function is passed back as a variable. This is a much more perferred option to setting empty variables from inside the pcall (not used in either example). This will work for any function where a result is returned.

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("NAME")
local suc,res = pcall(function()
   return DS:RemoveAsync("KEY")
end)
if not suc then
   console.warn(res)
end

Why res instead of error?
The old example just uses suc,err. The first variable, suc, is always going to be a boolean of whether the pcall executes without an error or not. The second variable is always a returning result. When an error occurs, that second variable will be an error, returned by pcall. You can instead return your own value for successes. This is why if not suc then is preferred over if err then.

Read more about pcall here: Pcalls - When and how to use them

11 Likes

So these are the exact scripts I use for both the datastore and global leaderboard, the stats save based on UserId. I’m unsure what determines the key of a datastore.

Datastore

image

Global Leaderboard

The key is generally the UserId. Or UserId with some text.
In this case your datastore names will be “rebirths” “mycookiedata” and “myrebirthsdata”
Your key appears to be the player’s userId (Integer) for both.

1 Like

So would the edited version of your script look somewhat like this?

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("myrebirthsdata")
local suc,err = pcall(function()
    DS:RemoveAsync(player.UserId)
end)
if err then
    console.warn(err)
end

Yes but player.UserId should be replaced with the userId of the user Roblox has requested you to remove.
Also do an else in the if statement if you want it to tell you that it’s completed.

1 Like

Like this?

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("myrebirthsdata")
local suc,err = pcall(function()
    DS:RemoveAsync(User's Id Here)
end)
if err then
    console.warn(err)
end
if success then
print("Removed")
end
4 Likes

That would work. But do if suc

1 Like

I think it’s working, removed is being printed

That means it ran successfully. Do that for each one of your datastores and it should wipe them off.

1 Like

Thanks so much, hopefully this is the only part of the website being effect by the right to erasure, none of my other games save data.