How to fully delete a GlobalDataStore?

I have a GlobalDataStore and I want to remove every stored value in it, basically same as doing this to a table

local array = {1,2,3,4,5}
array = {} -- Like this but for the GlobalDataStore

change the datastore key to something else.

3 Likes

Do you mean the name of the original DataStore? This will only create a new DataStore leaving the old one intact.

To achieve this you can nil every key (remove every entry) from the DataStore using RemoveAsync() or through using SetAsync() and setting the value to nil, once every item has been removed, the DataStore is essentially deleted (at least from an external point of view). It is possible that Roblox adds its own hidden keys to DataStores internally.

I don’t know what the keys are, so I can’t just loop thru them and RemoveAsync() one by one. Unless there a way to get all the keys in a GlobalDataStore?

There is no API for this (for a good reason, I may add). As others have mentioned, it is far easier to simply use a different data store entirely. The real question should be why do you want to do this?

That requires me to change my current GlobalDataStore’s name from PlayerData to something else, I don’t want to do that.

That’s not really the real question here, I am constantly testing my game and I sometimes want to delete everyone’s data and restart everything.

2 Likes

Then it sounds like you should apply a version number to your player data and have the game refuse to load any that isn’t acceptably up-to-date (i.e. pretend they’re brand-new if the integrity check fails). Clearing all the data store keys is never a good solution, and more importantly not a scalable one.

Again, the solution here with the lowest amount of work involved and highest chance of success is to just change the string, rather than engineer a solution.

Currently there is no way of doing this the simple way, I would need to RemoveAsync() key by key, so what I’ll start doing from now on is making two GlobalDataStore, one will hold everyone’s keys and the other their data, so if I ever need to wipe all the data, i’ll just loop thru those keys and RemoveAsync().

This might cause some complications depending on the size of your game, for example if your game had 1million players joined, you might run out of storage to store their keys in the second datastore.

I know it’s the lowest amount of work and will 100% succeed, but I don’t want to give up readability just for the sake of changing the datastore.

2 Likes

I assure you that even adding just one extra line of code for this will make everything far less readable than changing the string lol

But you should post your solution on this thread anyway once you’ve got something :slight_smile:

I am well aware of that fact, but I am still not giving up my current datastore’s name. Thanks for your help.

If you really care that much about the datastore name you can just re-publish the game.

2 Likes

Hello, late reply… But I recently made a plugin in beta, currently fully functional and allows you to delete datastores with time. Just search the datastore name then you can click destroy to remove all keys one by one.

https://create.roblox.com/store/asset/17799806895/Data-Editor-Version-02

1 Like