I´d like to know how to delete the Data of that deleted player. I´ve been looking around some related topics, but I did not find anything useful.
What would happen if I could not remove the Data? I´ve read nothing will happen, but I´d like to fix this.
This is the script of the DataStore of my game:
local DataStoreService = game:GetService(“DataStoreService”)
local dataStore = DataStoreService:GetDataStore(“MyDataStore”)
local plr = game:GetService(“Players”)
local function saveData(player)
local tableToSave = {
player.leaderstats.Exp.Value;
player.leaderstats.Level.Value;
}
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, tableToSave)
end)
if success then
print("Data has been saved!")
else
print("Data hasn't been saved!")
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(player)
local data
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success then
player.leaderstats.Exp.Value = data[1]
player.leaderstats.Level.Value = data[2]
else
print("The player has no data!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
saveData(player)
end)
if success then
print("Data has been saved")
else
print("Data has not been saved!")
end
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local success, err = pcall(function()
saveData(player)
end)
if success then
print(“Data has been saved”)
else
print(“Data has not been saved!”)
end
end
end)
The documentation basically just syas in a fancy way that it deletes the data of the user. Or in specific terms the data that has been saved to the unique key.
So, if you’ve been saving the data through userids (which you should’ve). Then all you need to do is something like this
Datastore:RemoveAsync(UserID)
And make sure you wrap it in a pcall.
Just write it in a random script and run it, then boom it’s gone.
Well, all you need to do is replace the “00000” with the ID you want to clear of the users data. Then, run this in the console on the server. Not in studio.
Don’t listen to @Miserable_Haven the code he is giving you makes no sense whatsoever
As pointed out by @Amritss, you can use :RemoveAsync() like so
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("MyDataStore")
local UserId = 000000 -- Put the UserId of the player in the Right To Erasure request
local success, err = pcall(function()
dataStore:RemoveAsync(UserId)
end)
if success then
print("Data has been cleared!")
else
print("Data hasn't been cleared!")
warn(err)
end
Change 000000 to the UserId and paste this code in the developer console, in studio or in a live game