How to delete everything in the datastore?

That is because the data store exists, it gets created by the AllFramesDataStore script but its simply empty, unless its writing new data in the script every time u join, but the script i gave u wipes it empty so when u join u have an empty datastore.

To be honest, I was 99.99% sure that the datastores were empty, but I would like them to not even exist in my game without re-creating the game. It may not sound like a big problem, but for me, it is a huge problem.

There is no need to re-create the game, if u never call them in any script its like they don’t exist

Okay, you are right, but the game will have huge data handling in the future because it will have a lot of data. I am not sure, but I think having all those empty datastores makes your Roblox game run out of memory. Okay, I know it sounds dumb or not, but I think that’s how it works. I am not saying I am right, I just don’t have this knowledge. Are you 100% sure there is no way to delete those empty datastores using a server script?

If a datastore has no data inside and its not called in any script via :GetDataStore() its like it doesn’t exist, I have also made a tweak to ur initial script that only deletes data if it exists, I don’t know if it 100% functional depending on how some datastores may save data but it should work

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)

				if KeyStore ~= nil then

					if string.len(tostring(KeyStore)) >= 1 then

						print(tostring(KeyStore))


						DataStore:RemoveAsync(Key.KeyName)
					end
				end
			end

			if KeysPages.IsFinished then
				break
			end

			KeysPages:AdvanceToNextPageAsync()
		end
	end

	if DataStorePages.IsFinished then
		break
	end

	DataStorePages:AdvanceToNextPageAsync()

	task.wait()
end

print("Done Deleting Data")```

Here is a video of what I mean:

Give me 1 minute, please. I am testing your script.

Unfortunately, it does the same thing as the main script. The only difference I can see is that the process is much faster.

Ohhhhh I see what u mean now friend :slight_smile: u can either try running the script i posted above in the command bar in studio and then press play it should fix things or u could try this script instead

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)

				if KeyStore ~= nil then

					if string.len(tostring(KeyStore)) >= 1 then

						print(tostring(KeyStore))


						DataStore:SetAsync(Key.KeyName, "")
					end
				end
			end

			if KeysPages.IsFinished then
				break
			end

			KeysPages:AdvanceToNextPageAsync()
		end
	end

	if DataStorePages.IsFinished then
		break
	end

	DataStorePages:AdvanceToNextPageAsync()

	task.wait()
end

print("Done Deleting Data")

both options should work either way, after running join the game ur problem should be fixed send me a screenshot

Thank you so much for trying to help me! Please give me one minute to test it.

Unfortunately, when I tested your new server script, it didn’t work as expected. It was still printing the data that should have been deleted from the test before. Also, we tried your command for the console before, but it didn’t work either. To be honest, I have a feeling we are close to find the solution.

There was just a very small tweak to the script that had to be done, it said it was deleting a datastore before checking if it has any data

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)

				if KeyStore ~= nil then

					if string.len(tostring(KeyStore)) >= 1 then

						print(tostring(KeyStore))
                        print("Deleting: " .. Key.KeyName)


						DataStore:SetAsync(Key.KeyName, "")
					end
				end
			end

			if KeysPages.IsFinished then
				break
			end

			KeysPages:AdvanceToNextPageAsync()
		end
	end

	if DataStorePages.IsFinished then
		break
	end

	DataStorePages:AdvanceToNextPageAsync()

	task.wait()
end

print("Done Deleting Data")

this is the fix most likely, the reason why it was still printing is because its not possible to fully delete a datastore once it has been created only its data, but if its empty it shouldn’t be an issue

I tested your new server script, and I think the only difference now is that you removed the print for the keys. Also, I tested your server script, and it said that it deleted all the data, so I disabled your server script and enabled the old one to see if it actually deleted all of the data, but unfortunately it didn’t. Thank you so much for trying to help me. I really appreciate it! Do you have any other suggestions?


(Sorry for the bad quality of the video and for the bad frame rates of the video.)

i didn’t delete the print I moved it, it only prints if the datastore is not empty quoting what i said in my last message the reason why it was still printing is because its not possible to fully delete a datastore once it has been created only its data, but if its empty it shouldn’t be an issue

So there is zero percentage to make my game out of memory because of this?

There is no memory consumed if the datastore is empty, roblox doesn’t have a way to fully delete a datastore

try this script to see for urself the datastores are empty

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(Key.KeyName.." data is "..KeyStore) -- if it says instance that still means its empty
				if KeyStore ~= nil then

					if string.len(tostring(KeyStore)) >= 1 then

						print(tostring(KeyStore))
                        print("Deleting: " .. Key.KeyName)


						DataStore:SetAsync(Key.KeyName, "")
					end
				end
			end

			if KeysPages.IsFinished then
				break
			end

			KeysPages:AdvanceToNextPageAsync()
		end
	end

	if DataStorePages.IsFinished then
		break
	end

	DataStorePages:AdvanceToNextPageAsync()

	task.wait()
end

print("Done Deleting Data")

Alraight! Thank you so much for all your help until now. It was very important for me. I was just thinking it would be very exhausting for data handling, which is why I wanted to delete them. But if you are saying there is no way to delete the datastore, okay, man, I trust you. My game will use tons of data, which is why I was a bit scared. I mean scared out of memory. If I have future programming issues like this one, I will mention you in my future forum¹ because, man, you explained it very well, and I really appreciate it.

Also, I tested your new server script to see what would happen, and this is what happened:
image
I can understand that the datastore is empty (nil).

¹ Do I have your permission to mention you if I have programming issues in a future post?

Sure thing!, yea it probably errored cause it was empty

try this should print now

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(Key.KeyName.." data is "..tostring(KeyStore)) -- if it says instance that still means its empty
				if KeyStore ~= nil then

					if string.len(tostring(KeyStore)) >= 1 then

						print(tostring(KeyStore))
						print("Deleting: " .. Key.KeyName)


						DataStore:SetAsync(Key.KeyName, "")
					end
				end
			end

			if KeysPages.IsFinished then
				break
			end

			KeysPages:AdvanceToNextPageAsync()
		end
	end

	if DataStorePages.IsFinished then
		break
	end

	DataStorePages:AdvanceToNextPageAsync()

	task.wait()
end

print("Done Deleting Data")