How do i delete everything in a datastore key?

So i basically want to delete everything inside of my datastore key called “TwitterCodes” any help will be appreciated.
my code:

local datastore = game:GetService("DataStoreService")
local aDataStoreServer = datastore:GetDataStore("TwitterCodes")
local codelist = {
	"Test",
	"Test2"
}

game.Players.PlayerAdded:Connect(function(Player)
	aDataStoreServer:GetAsync(Player.UserId.."-Code1")
	aDataStoreServer:GetAsync(Player.UserId.."-Code2")
	aDataStoreServer:GetAsync(Player.UserId.."-Code3")
end)

game.ReplicatedStorage.Redeem.OnServerEvent:Connect(function(Player, valueo)
	if table.find(codelist,valueo) then -- Replace the Quotation text with your twitter code
		if not aDataStoreServer:GetAsync(Player.UserId.."-Code2") then
			aDataStoreServer:SetAsync(Player.UserId.."-Code2", true)
		end
	end
end)
1 Like

Datastore Built-In Functions


Datastores have a few built-in functions like:

  • GetAsync(key) ← Recieve current data
  • SetAsyc(key, value) ← Saves new data
  • UpdateAsyc(key, function(currentData) ← Obtain and save new data in a function
  • IncrementAsync(key, value) ← Increases the data numbers (negative subtracts)
  • RemoveAsync(key) ← Wipes their data from the datastore

More information here

2 Likes

thanks for the help! but i wanted to delete every single value of every player

Unfortunately, there’s no way to delete an entire datastore. Only other way would be to rename the datastore name in the script.

2 Likes

Actually it is possible to delete all data by going through the list of async keys and removing each one. For warning this will delete all datastores for that game not an individual datastore if you had more than one datastore in the game.

I’d also scroll down a little bit in the community thread since some fixes were made to the code.

1 Like

You can use a data store editor to do this like this one: Super Biz Data Store Editor – Free, Web-Based, Powerful Editing, Simple UI

Disclaimer: I work on this.

it wants a Age Demographics which the game isnt old enought to retrieve/isnt public

well i can try renaming the datastore

and im gonna try this script out two

I mean thats not fully true. You can set all the values to nil and replace them to whatever you wish later. That way it doesn’t take up any space because its storing nothing. So do SetAsyc(key, nil) and those values will come up as nil. It technically won’t be gone but it definitely wouldn’t give you anything when calling on it until its changed.

He meant to clear an entire DataStore from every single key. I already showed him how to clear a key but I that’s not what he was asking.

i meant only 1 key with all of the player data inside

He could just rename the data store or when a player joins remove their data for that data store

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.