How would I delete all data from DataStores

pfr.DSS = game:GetService("DataStoreService")
pfr.Str = pfr.DSS:GetDataStore("A-")  -- How Would I Delete All Data from this?

Not remove the DataStore, but Delete all inside it

And Also, how would I get a List of DataStores created?

2 Likes

Seems like this forum had a similar problem to yours.

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("YOU DATASTORE NAME")

local Success, Pages = pcall(function()
	return DataStore:ListKeysAsync()
end)

while task.wait() do

	local Items = Pages:GetCurrentPage()

	for _, Data in ipairs(Items) do

		local Key = Data.KeyName
		DataStore:RemoveAsync(Key)

	end

	if Pages.IsFinished then break else Pages:AdvanceToNextPageAsync() end

end

print("Done")

I’m not sure if you can delete a key from a DataStore, however I have this script which will reset all data stored to any key in a DataStore you give it. I always run this in the command bar in studio to wipe data.

4 Likes

You CANNOT delete data store data. No possible way. You’re gonna have to create a new data store. Dont look for ways to, trust me. You cant

1 Like

you could “Delete” data by setting the Data as nil, but that would be a weird way of doing it

Isn’t :RemoveAsync() meant just for that?

Thats not deleting it. Thats just setting all the data to nil. I wish there was a way to actually delete it

People really dont understand text. “Delete”, Quotation Mark

I didn’t really see that. Sorry, my bad, es tut uns leid, perdón, scusa

If you wish to remove a key from a DataStore then I would have to side with @PahcaPower on this one as I’ve done my own research and haven’t found a way to do it. However, setting every key’s data to nil is practically deleting it. But if you are dead focused on deleting the keys, switching to a new DataStore is a better option.

Not Remove a Key, Remove Data in a Key, I know its impossible to remove the DataStore.

Then the script I provided should do the job.

You can do this by iterating through the versions of the keys and deleting them one by one. This will not only set the key to nil, but it will also delete the history of the key, the history Roblox keeps for 30 days.

Not sure if this suits your needs, but a cheap, cheat way to do it is to just delete the leaderstats / other folders from under the player when they join (PlayerAdded). this essentially means you’ve deleted the values that are communicated from the datastore, but it’s not really the same as actually deleting one.

I dont think you understand how DataStores work.

I do, hence why I said “cheap, cheat”. It doesn’t really delete the datastore, so I understand where you’re coming from, but it technically removes your access to it. I don’t really know how to word it…

Im not using leaderstats btw

hence why i also said “other folders”.

Not using Folders either

How are you storing the values then? Just putting them straight under the player?