Script that can remove all data stores in your game

This is for people (like me) who are creating new Data Stores every time, I saw a lot of developers struggling with this in the devforum and apparently no one knew how to delete data stores but here I am to save the day
Basically the script goes through all data stores, then through all keys in each data store and removes them with :RemoveAsync()
And you should definetly take caution when using this script cuz once you run the game it erases all the game’s data stores and there’s no going back

local DSS = game:GetService("DataStoreService")

local DataStorePages = DSS:ListDataStoresAsync()

while true do
	local CurrentStoresPage = DataStorePages:GetCurrentPage()
	
	for i, DataStoreInfo in pairs(CurrentStoresPage) do
		
		local DataStore = DSS:GetDataStore(DataStoreInfo.DataStoreName)
		local KeysPages = DataStore:ListKeysAsync()
		
		while true do
			local CurrentKeysPage = KeysPages:GetCurrentPage()
			
			for j, Key in pairs(CurrentKeysPage) do
				DataStore:RemoveAsync(Key.KeyName)
			end
			
			if KeysPages.IsFinished then break end
			
			KeysPages:AdvanceToNextPageAsync()
		end
	end
	
	if DataStorePages.IsFinished then break end
	
	DataStorePages:AdvanceToNextPageAsync()

	task.wait() --you might want to remove this line
end
70 Likes

Where is the documentation for :ListKeysAsync()? It does not exist on the API Reference under the GlobalDataStore or OrderedDataStore instances.

GlobalDataStore | Roblox Creator Documentation
OrderedDataStore | Roblox Creator Documentation

Never mind - the API reference is bugged. It should be listed under those instances as they never say they inherit the DataStore functions.

https://developer.roblox.com/en-us/api-reference/function/DataStore/ListKeysAsync

1 Like

Keep in mind - you may want to add a task.wait() at the end of the loop as to not freeze Studio.

1 Like

I know this post was a while ago but I think that people still see it. All I need to say is that if you get an error for these lines:

				if KeyStore then --printing all the data found inside that key of the data store
					for index, value in pairs(KeyStore) do
						print(index, value)
					end
				end

Then just delete them, you don’t need it. Other than that this script works extremely good so thanks for making it.

Edit: And if you don’t know how to use it just put it in ServerScriptService and playing the game until it stops printing in output.

Edit2: And if you don’t know when it stops printing just put print("done deleting data") at the end of the script, and when you see that in the output you know it’s done.

Edit3: If you don’t understand then here is the edited script:

wait(3)

local DSS = game:GetService("DataStoreService")

local DataStorePages = DSS:ListDataStoresAsync()

while true do
	local CurrentStoresPage = DataStorePages:GetCurrentPage()

	for i, DataStoreInfo in pairs(CurrentStoresPage) do

		local DataStore = DSS:GetDataStore(DataStoreInfo.DataStoreName)
		local KeysPages = DataStore:ListKeysAsync()

		while true do
			local CurrentKeysPage = KeysPages:GetCurrentPage()

			for j, Key in pairs(CurrentKeysPage) do
				local KeyStore = DataStore:GetAsync(Key.KeyName)

				print("deleting " .. Key.KeyName .. "...")

				DataStore:RemoveAsync(Key.KeyName)
			end

			if KeysPages.IsFinished then break end

			KeysPages:AdvanceToNextPageAsync()
		end
	end

	if DataStorePages.IsFinished then break end

	DataStorePages:AdvanceToNextPageAsync()

	task.wait() --you dont need this line if your data isnt too big
end

print("done deleting data")
29 Likes

where do we put this? or am I blind

workspace or serversscriptservice

2 Likes

You could also run this in Roblox Studio via Console

4 Likes

It seemed like this was working for a bit, but then it gave me this error:
502: API Services rejected request with error. HTTP 429

Even though the task.wait() line was there.

I tried adding a wait(5) before this:
local CurrentKeysPage = KeysPages:GetCurrentPage()

And it worked for a decent amount of time! But then I got this error:
HTTP 500 (InternalServerError)

Make it yourself, you are a programmer

Retry using pcall and make the task.wait parameter bigger

DataStore functions all have limitations, you cant call them too much or else roblox doesnt allow it. For the :RemoveAsync() method, the limitation is 60 + numPlayers × 10 requests per minute so maybe you’d need to modify the script a bit by adding a task.wait(60) before the limit is reached

Thanks so much for this script. I’ve been looking for this for a long time and only found this now. However, I’m getting an error "Not running script because past shutdown deadline (x31) " is this because I have too many data store entries and even after I stop the game, it still has more to go through?

Also, I assume I don’t have to change anything with the code, such as telling it which datastore to choose?

You dont have to change anything to the code, it gors through every data store.
The error is probably being caused because you exceeded the ammount of :RemoveAsync() you are allowed to use per minute, try to add a task.wait(1) right after :RemoveAsync().

1 Like

This does not seem to work, My tools datastore still exists and loads properly.

Bumping because of this post:

did you put it in server script service and wait until the output said ‘done deleting data’?

Yeah.

It may be that I am using datastore2 but still

Ill try disabling my data manager script and then see if that works

EDIT:
That fixed it however is there a way I could do this just for one player only? For a save data reset function in my game