How do I remove a data store key completely

I made a datastore with a key Won_myuseridhere but even tho I deleted the stats on it, it still apparently exists

apparently you’re supposed to set the key to nil

But the key has no data so nothing can be set to nil

I used a data store plugin to check the datastore and I tried to use the data store v2 and clicked the “list keys” button and it showed me that the key tag I already removed is still listed

Im assuming you already used removeasync function for datastores?

I’ve read often that you can’t inherently remove a key so I’m not entirely sure, the key would exist as set to nil.

idk if this would work and I cant really test since I cant use studios rn, but try something like
table[key] = nil

I have already tried removeasync

I dont quite understand what you mean. You created a Datastore and you created a Key in that DS, called “Won_myuseridhere” which contains a value, lets say “something”

You used RemoveAsync to remove that key in DS, but how do you know that “apparently still exist”?

You can run this code in command bar to check the behaviour:

local DSS = game:GetService("DataStoreService")
local TestDS = DSS:GetDataStore("TestDS2")

-- Save the key with value
TestDS:SetAsync("Won_myuseridhere", "something")

-- Read the key to print the value
local DATA = TestDS:GetAsync("Won_myuseridhere")
warn("value in key:", DATA) -- should print "something"

print("waiting 5 seconds")
task.wait(5) -- cooldown

-- Remove the key
TestDS:RemoveAsync("Won_myuseridhere")

-- Read again to check if key still exist
local DATA = TestDS:GetAsync("Won_myuseridhere")
warn("value in key:", DATA) -- should print nil so key no longer exist
1 Like

In Roblox, when you use the DataStore:RemoveAsync(key) function to remove a key from a DataStore, the key-value pair is removed from the DataStore. However, due to the way that Roblox’s DataStore system is designed, the key may still be considered to exist for some time after it has been removed.

This is because the DataStore system uses a distributed database, which may take some time to propagate changes across all servers. As a result, if you try to fetch a key immediately after deleting it, it might appear to still exist, even though it has actually been deleted.

If you’re testing whether a key exists by checking whether its value is nil, you may run into issues because DataStore:GetAsync(key) will return nil both if the key doesn’t exist and if the key’s value is nil.

If you want to completely clear a key-value pair from the DataStore and ensure that it doesn’t “appear” to exist afterwards, you might want to consider setting its value to a special sentinel value (like the string "deleted" or a unique value that you can recognize) instead of removing it. Then, when you fetch the key, you can check if the value is equal to the sentinel value to see if the key has been “deleted”.

It’s also worth mentioning that DataStore operations can occasionally fail due to various reasons, such as temporary network issues or Roblox maintenance, so it’s always a good idea to handle errors and use retries with exponential backoff for DataStore operations. This will make your game more resilient and provide a better user experience.

2 Likes

Use the :RemoveAsync(key) method to do it.

1 Like

When I used the data store plugin it says that the key is still listed and the myuseridhere is my user id

You mean this plugin? Honestly I never tried it… Could be an issue related with the plugin itself?

If not, and thats how the DSS works, that once a Key is created in the DSS table, its impossible to delete it and just overwrite it. Reminds me stuff like “its not possible to delete a place from your account”, its “not possible to delete assets uploaded”, I suppose DSS are not possible to fully delete.

But whats the issue? when you do GetAsync(key), and it returns nil in your script, you have everything to continue with your program, key doesnt exist as far as the query and script-wise returns. So no need to worry if “for that plugin the key still exist”… still nil.

I would prefer the key literally disappear, I didnt know it doesnt cause I never used that plugin you mentioned, but, still irrelevant, the key is nil, and thats all that matter script-wise


Im gonna test the plugin, yeah, why not