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.
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