How to delete everything in the datastore?

I want to make a server script that will delete all types of data from my Roblox game. I tried to find similar forums on Dev Forum, and I only found a very useful script, and in today’s forum we will use this as a template. I would like to make that server script delete all keys and tables. The current server script only deletes the keys.

-- Made by: Bikereh (1245828306)

-- Wait for 3 seconds before starting execution
wait(3)
-- Get a reference to the DataStoreService
local DSS = game:GetService("DataStoreService")
-- Retrieve a list of all available DataStores asynchronously
local DataStorePages = DSS:ListDataStoresAsync()
-- Continuously loop through each page of DataStores
while true do
    -- Get the current page of DataStores
	local CurrentStoresPage = DataStorePages:GetCurrentPage()
	-- Iterate through each DataStore in the current page
	for i, DataStoreInfo in pairs(CurrentStoresPage) do
		-- Get a reference to the current DataStore
		local DataStore = DSS:GetDataStore(DataStoreInfo.DataStoreName)
		-- Retrieve a list of keys in the current DataStore asynchronously
		local KeysPages = DataStore:ListKeysAsync()
		-- Continuously loop through each page of keys in the DataStore
		while true do
			-- Get the current page of keys
			local CurrentKeysPage = KeysPages:GetCurrentPage()
			-- Iterate through each key in the current page
			for j, Key in pairs(CurrentKeysPage) do
				-- Retrieve the value associated with the current key
				local KeyStore = DataStore:GetAsync(Key.KeyName)
				-- Print a message indicating that the key is being deleted
				print("Deleting: " .. Key.KeyName)
				-- Remove the key from the DataStore
				DataStore:RemoveAsync(Key.KeyName)
			end
			-- Exit the inner loop if all keys have been processed
			if KeysPages.IsFinished then
				break
			end
			-- Move to the next page of keys asynchronously
			KeysPages:AdvanceToNextPageAsync()
		end
	end
	-- Exit the outer loop if all DataStores have been processed
	if DataStorePages.IsFinished then
		break
	end
	-- Move to the next page of DataStores asynchronously
	DataStorePages:AdvanceToNextPageAsync()
	-- Wait for a short period before continuing the loop
	task.wait()
end
-- Print a message indicating that data deletion is complete
print("Done deleting data")

Also, I tried to write as many comments as possible on his server script so it would be understandable for you guys.

3 Likes

Please let me know if you know how to solve it! :happy3:

What do you mean by “only deletes the keys”, isn’t that what your datastore is comprised of? If you could show how you save your data, that would help, because deleting every key should mean your datastore is fully cleared.

Example:

Fully populated datastore:

{
	[13134] = {Coins = 10},
	[45436] = {Coins = 200},
	[67834] = {Coins = 150}
}

Datastore after removing all keys (aka the ids and their values):

{}

Hello @Katrist! :happy1:
Thank you so much for trying to help me. If you go to a game for only testing and run for the first time this script with some data in the datastore, you will see it actually works. But if you rejoin, it says the same thing. I want to delete everything. That’s what I mean.

Delete the script or change the name of the datastore. I’m not great with datastores, but I assume this will be able to do the trick. Not 100% sure though, so don’t be confident that I’m right.

Right, so if you have a datastore key, change it to anything else, other than what you currently have. For instance, if you have “Store1” as your key, change it to “Store2” and it will have a whole new data save. If you want to do it the harder way, you can re-upload the game as another game and you will reset everything.

I can’t re-upload the game. Is there any other way using the server script?

Look for where your datastore key is, aka the name, after you change it everything resets.

Is it possible to delete the datastores with only the server script?

Yeah, the thing is, I don’t even have those datastore keys, and it keeps deleting them.
image
image

Note that I am a kind of newbie on scripting and specifically on datastores, so if I am very bad on datastores, please do not be mean to me.

Hey @Katrist! The thing is, I don’t even know how the datastores even exist, which is why I want to delete them. You can see what I mean here. Also as I said before I am a kind of newbie on scripting and specifically on datastores, so if I am very bad on datastores, please do not be mean to me.

Hey guys, I still need some help… :sad:

I could help you but, first tell me what’s your problem

If that is where your datastore has been typed inside of, then yes. Sorry by the way. I thought this topic got solved tbh.

Hello @Otiko_SecretBC! Okay, so I found a script, and it should delete all data from the datastore. When I join the game, it starts printing that it deletes the keys, and it actually works, but when I rejoin, it says the same thing. I want to delete everything and make it not print anymore because the data won’t even exist. Also, I am a newbie at scripting, specifically at datastores.

1 Like

After you delete datastore just save data, so when you rejoin you won’t have any data, because it will be empty

It is okay, @Wizzthepixelcat. Let me remind you of my problem. When I join the game with this server script on the ServerScriptService, it starts printing that it actually deleted datastore keys. Example:
image
After that, the datastore keys actually doesn’t exist, but when I rejoin after the datastore deletion, it keeps printing this:
image

1 Like

I will save data, but because when I am testing a game and messing up with the datastore, I want it fully deleted, like a baseplate’s (new game’s) datastore.

I’m not sure what to do about this one. Sorry. :grimacing:
I’ll be seeing myself out of this one. I hope you get the help that you need. You can try purchasing “Datastore Editor” for 100 robux. It sadly isn’t free obviously, but just letting you know that you can try this if need be. I have no idea if refunds exist, so buy it at your own risk. It has really good reviews though.