Erasing Player Data

What do you want to achieve?

I am making a game and I want to be able to erase a player’s data automatically when they press/click a button.

What is the issue?

If I change the DataStore then it will erase everyone’s data
Plus I would have to do it manually

What solutions have you tried so far?

I looked on google and found no results.

You can change every value to 0 once they click the button. Then fire the server to update the values and save the datastore.

1 Like

When they press a button, you will fire a RemoteEvent from that client to the server, assuming you’re working with GuiButtons. The server will have to default all values, and you can call RemoveAsync on the datastore to remove the player’s data from the datastore

You don’t want to delete the entire DataStore! You should be removing the player’s key from said DataStore.

Script.Parent.MouseButton1Click:Connect(function()
       RemoveAsync()

What would go before/after the RemoveAsync?

That’s a LocalScript, right? You can’t alter DataStores from the client. (That would be a big security risk!)


-- This assumes you have a RemoteEvent in ReplicatedStorage named EraseData

-- Client script
---------------------

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.EraseData:FireServer()
end)

-- Server script
-----------------

-- This assumes you've declared the var DataStore as the store you've been using

game.ReplicatedStorage.EraseData.OnServerEvent:Connect(function(Player)
	local Key = Player.UserId -- or whatever you've been using to store play data
	DataStore:RemoveAsync(Key)
end)
7 Likes

Or you could set all the data in that key to zero, or nil.

Yes, that would effectively reset as well. However, he stated in the OP that he wants to erase data (not just set to default) so that’s what I answered.

For example, handling a Right to Erasure request is not satisfied by simply resetting, but you need to fully remove it.

Removing the key and setting it to zero are two different circumstances. In some cases where your DataStore handler is expecting a nil value for no data, a 0 value would produce unintended results and create errors in your code.

RemoveAsync is the proper way to erase and remove a player’s data, not setting it to a different value.