Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to remove Datastore from offline players?

Asked by 3 years 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 3 years 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 212 — 3y
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 — 3y
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 212 — 3y
Ad

Answer this question