Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to delete a player's data in datastore?

If a player wants to start a new game, how would I delete their data in the datastore

2 comments

0

You can just reset all the values, or do the same thing you do to a new player that enters the game, give them a new data set...

0

The simplest way would be to make a new key as you caould the port data over. To delete all of the data we would need to know how it is stored. ps cool hat.

1 answer

✓ Accepted answer

Overwriting keys

Using DataStoreService, the only way you can change a value is by overwriting the former. The same thing applies with removing keys or values as well. Just like how you'd "remove" a variable in a script by setting it to nil, you'd do the same thing in data store with whatever set method you're using (SetAsync, UpdateAsync, etc) - just save a nil value. Here's an example:

local data = game:GetService("DataStoreService"):GetDataStore("Test")
data:SetAsync("Key", "Hello there") -- Assign a value

wait(10) -- Keep the value for 10 seconds

data:SetAsync("Key", nil) -- Essentially removing the value.

That's about it, simple as that. Let me know if you have any questions!

3 comments

0

So I just have to reset their values to 0

0

Well, if you want their saved data to return 0, yes. But if you want the value completely gone, you'd set it to nil as demonstrated in the example.

0

Last time I did that, I had to write on line one data:SetAsync(key, {})

This discussion is preserved as it was. New answers, comments, and votes are closed.