Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to delete a player's data in datastore?

Asked by 8 years ago

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

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... dragonkeeper467 453 — 8y
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. User#5423 17 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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!

0
So I just have to reset their values to 0 NovaMagic 73 — 8y
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. ScriptGuider 5640 — 8y
0
Last time I did that, I had to write on line one data:SetAsync(key, {}) greatneil80 2647 — 6y
Ad

Answer this question