How to remove data from datastores within your game?

I was wondering how it would be possible to remove data from datastores with just an UserID.

I have checked the developer page for this and it shows this:

local DataStoreService = game:GetService("DataStoreService")
local nicknameStore = DataStoreService:GetDataStore("Nicknames")
 
local success, nickname = pcall(function()
	return nicknameStore:RemoveAsync("Player_1234")
end)
 
if success then
	print("Removed Nickname:", nickname)
end

But the above code only seems to remove them by a username, not an UserID.

Any help would be appreciated as I need this asap.

3 Likes

How are your keys formatted? Do you just use the user ID or do you add a prefix/postfix?

Just change the key to userId. DataStore:RemoveAsync(userId) instead of the username.

2 Likes

First of all, RemoveAsync accepts a key for the record you want to delete. So when you want to remove the data record, you will have to pass the key you used previously while storing that player’s data.

2 Likes

Not too sure what you mean by this, I got an message stating I need to remove someone’s UserID as of the data laws.

Edit: Seems I only used the UserID, but for some of them I used a prefix so I just changed the “Player_” to fit the prefixes of them.

However, I did use a plugin by someone and it seems to of done the trick, however, I will be double checking I have done all of the steps correct tonight as I do value people’s requests on data.

I’ll try that now, thank you so much.

1 Like

Alright, so I have changed it to the UserID:

local DataStoreService = game:GetService("DataStoreService")

local nicknameStore = DataStoreService:GetDataStore("Nicknames")

local success, nickname = pcall(function()

return nicknameStore:RemoveAsync("ID goes here")

end)

if success then

print("Removed Nickname:", nickname)

end

Just wanted to make sure this was right & how would I execute this to make it remove the data.

Would I just add this to a script and join the game?

1 Like

If the player User Id is the Key you have used earlier for saving their data, then yes that should work.

Alright then, I can’t remember using any key to do it, so I am guessing this should work.

I will try it and see.

Thanks so much for your help also, I really do appreciate it.

1 Like

If that isn’t the key though, it won’t be removed, you could have a look through your game’s Data saving script and you will probably get the key you used from there.

Hmm, would this script just be inside of my game files, or would there be another place I need to look for it. (Sorry if I seem a bit slow to this, it is just that I have never needed to do this before.)

I mean, you probably have a Data saving script or probably know where you save your player’s data in your game right? in it if you use like SetAsync, GetAsync or UpdateAsync methods, you will pass a key, that is the key you want to remove for that player.

Ah I see, I think I am looking inside of the wrong game, so I will look through my others and see if I can see a key being passed through.

I will reply here if I am stuck or unsure, but yeah, thank you.

Edit:

I have managed to find all of the datastores that have been mentioned inside of my scripting by using Ctrl+Alt+F and searching for “SetDataStore”, this came up with all the datastores.

And then I found the keys were just the players UserID, so I used a plugin made by a user on roblox and a script which was made on the developer information site to remove all of the instances inside of the datastore of the user.

Like I say, thanks so much for everyone replying here, it really does mean a lot and I am not too sure what I would of been like if it wasn’t for you guys helping me. Just hoping with everything that I did was right.

1 Like

setting it to nil will remove it

Yeah I followed this tutorial by roblox to remove it (it used “RemoveAsync” to remove the values by the data key) and also a plugin made by someone on roblox.

Hopefully this should of done the trick, but I will test doing setting the values to nil some time later.

Edit: I have used a command which verifies if there is any data inside of the tables, there is none found for the user in question so I think I have done everything right. When I used my ID for it, it appeared that some results were shown for it as supposed to the other user, which showed none (printed back blank).

Let me know if there is anything else I should do, as I think they requested their data to be removed from my old game which has been overwritten by a new game a few months back, so their id wouldn’t be inside of my scripting. So I am only guessing I can clear them from the datastores.