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
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")
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().