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

How to remove Datastore from offline players?

I have a leaderboard in my game and a player cheated their way up and now the player has stopped playing the game. How will i remove the player from the leaderboard. i have tried

local DataStoreService = game:GetService("DataStoreService")
local coinsDataStore = DataStoreService:GetDataStore("CoinsDataStore")


-- replace 123 with the proper User ID
coinsDataStore:RemoveAsync(123)

with the datastore name and user id but it did nothing when i ran it on the cmd bar.

1 answer

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
	--Replace with User Id

	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
	--Replace with User Id
	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

0

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

0

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.

0

get the players id, write a script to remove it (the player does not have to be there for datastore requests to happen)

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