Intro
I am making this tutorial since I’ve seen not many people actually know how to effectively wipe everyone’s data from a datastore. So I am making one to inform people.
Why not simply make a new datastore?
Data stores behave similarly to tables in databases. Minimize the number of data stores in an experience and put related data in each data store. This approach allows you to configure each data store individually (versioning and indexing/querying) to improve the service’s efficiency to operate the data. As more features become available, this approach also allows you to more easily manage data stores.
So, how do I wipe the data?
Simply using the :ListKeysAsync() method which returns a datastorekeypages object.
local Pages = Datastore:ListKeysAsync("", 50)
Listkeysasync has multiple parameters, you may want to change the pagesize parameter which is the second parameter in the method to determine the maximum amount of items that can be returned. The default value is 0.
Now that we have our datastore pages object, we can get the current page.
local Pages = Datastore:ListKeysAsync("", 50)
local Page = Pages:GetCurrentPage()
You now have an array of pages, since datastorekeypagesobject is a special type of page object. It returns keyinstances which you can use while looping through the array of the page.
for _, KeyInstance in Pages do
Datastore:RemoveAsync(KeyInstance.KeyName)
end
KeyInstances have a property called “KeyName” which you can use to find a player’s specific key and remove that player’s data.
ListKeysAsync can retrieve all keys that are within your datastore, jsut mess around with the second parameter if you haven’t retrieved all of them.
For more information on listkeysasync see here: DataStore | Documentation - Roblox Creator Hub