Try making an event, if the player joins the game, check their id and if their Id is the Id you want to erase data from you can then remove their data or you could set their data to zero
Example:
local datastore = game:GetService("DataStoreService")
local coinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local id = 123
if player.UserId == id then
coinsDataStore:RemoveAsync(id)
print("Your data has been deleted")
else
print("Wrong player")
end
end)
Or:
local datastore = game:GetService("DataStoreService")
local coinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local id = 123
local data = coinsDataStore:GetAsync(player.UserId)
if player.UserId == id and data ~= 0 then
coinsDataStore:SetAsync(player.UserId, 0)
print("Your data has been deleted")
else
print("Wrong player")
end
end)
Once the player's data has been erased you can remove the script.
I hope this was helpful
3 comments
if they are offline put it in a while loop, don't put if statements(only to check if their data is bigger than 0), and set their data to zero
But what if the player never joins back again and they stay on leaderboard? I want to remove their data in a way that they do not have to join.
get the players id, write a script to remove it (the player does not have to be there for datastore requests to happen)