Right to Erasure Automation Script

Hey all,

I haven’t posted anything on the dev forums yet but I thought this would be a good thing to start with.

I run a fairly large game with around 13 million visits at this point in time and I have never checked my personal Roblox messages because I didn’t think there would be a need to. Well I couldn’t have been more wrong about that, when I checked them today I was flooded with messages titled [Important] Right to Erasure - Action Requested with a user id and a link to my game telling me to delete all data associated with this user id in the game, data stores, etc.

I had about 20 of these messages with different user ids and I have 4 data stores in my game, 1 normal data store and 3 ordered data stores so if you do the math that’s 80 entries that I had to delete which isn’t the worst but it’s also pretty tedious to do one at a time. I thought somebody must’ve made a plugin or script for this but I couldn’t find anything so I decided to make a quick script that I could just paste in the command bar in Roblox Studio and this is what I came up with.

local DataStoreService = game:GetService("DataStoreService")

-- Add all of your datastores here with all the relavent information for each one
local dataStores = {
  {
    dsName = "MyDatastore1", -- Name of the data store
    dsType = "Regular", -- Type of the data store, either Regular or Ordered
    prefix = "Player_" -- If you use a prefix with the user id you can add it here, for example "Player_[userid]"
  },
  {
    dsName = "MyDatastore2",
    dsType = "Ordered",
    prefix = ""
  },
  {
    dsName = "MyDatastore3",
    dsType = "Ordered",
    prefix = ""
  }
}


-- Put all your user Id's in this array
local userIds = {
  "User id 1",
  "User id 2",
  "User id 3"
}

-- Loop through the datastores provided
for i, datastoreData in pairs(dataStores) do

  -- Loop through the userId's provided
  for i, userId in pairs(userIds) do
    local success, data = pcall(function()

      -- Check what type the datastore is because we either need to use DataStoreService:GetDataStore or DataStoreService:GetOrderedDataStore
      if datastoreData.dsType == "Regular" then
        local datastore = DataStoreService:GetDataStore(datastoreData.dsName)

        -- Remove the data entry associated with that userId if there is one
        return datastore:RemoveAsync(datastoreData.prefix .. userId)
      elseif datastoreData.dsType == "Ordered" then
        local datastore = DataStoreService:GetOrderedDataStore(datastoreData.dsName)

        -- Remove the data entry associated with that userId if there is one
        return datastore:RemoveAsync(datastoreData.prefix .. userId)
      else

        -- This is just here incase of a typo in the type of Datastore provided
        print("Unknown data store type: " .. datastoreData.dsType)
      end
    end)

    -- I have these here to show if the call was successful or not
    -- Note: Just because it says successful that doesn't mean anything was deleted, it just means that the data store didn't return an error
    print("Success (" .. userId .. "): " .. (success and "True" or "False"))

    -- If this prints any data, that's the data that was deleted
    print(data)
  end
end

A warning before you use this code:

I don’t claim to be the best programmer in the world or know a ton about best practices when it comes to data stores and this is something I threw together fairly quickly so if you choose to use it, it’s at your own risk! I would recommend reading through the script and understanding what it’s doing before you use it, I’m not the best at commenting my code but I tried to add some helpful comments.

Than being said it seemed to work perfectly fine when I ran it and deleted all 80 entries in a couple of seconds. If you know of a better way to do this I would love to hear how you do it or if you have suggestions on how to improve it I would also love to hear about it. Hopefully this helps some of you out!

Directions for use:

  1. Copy the code into a text editor of your choice
  2. Edit the “dataStores” array and add in all of the data stores you want to delete the player data out of
  3. Edit the “userIds” array and add in all of the user ids you want to clear from the data stores
  4. Copy and paste the edited code into the command line at the bottom of Roblox Studio
  5. (Optional) Clear the command line output by clicking the brush in the upper right
  6. Press enter in the command bar and watch the print statements to see what is happening
9 Likes

This works really well. Thank you so much!

1 Like