Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to remove Datastore from offline players?

Asked by 17 days ago

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

Log in to vote
0
Answered by 17 days ago

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

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 NathanBlox_Studios 100 — 17d
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. sign_there 0 — 16d
0
get the players id, write a script to remove it (the player does not have to be there for datastore requests to happen) NathanBlox_Studios 100 — 16d
Ad

Answer this question