I have stumbled across an interesting issue when I was testing with my leaderboard. To begin with, I have leaderstats set up for Coins.
Likewise, I also happen to have a in-game leaderboard that displays who has the most of this currency. But if there is an exploiter who appears to be cheating on this leaderboard, I want to reset their data.
The problem is, I don’t know how I could reset their data if they are offline and not in the game. I can’t get into a server with them. That brings me to the question: How could I reset someones points if they aren’t in the server, globally? So they disappear off this leaderboard. Without me having to be in a server with them.
I have tried looking through posts but haven’t found any solutions.
I’m not really sure if I understood your question or not, are you trying to reset stats of an offline user? If so you can simply paste this in the command bar.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("YourDataStoreName")
local PlayerUserId = -- The player's UserId
DataStore:RemoveAsync(PlayerUserId) -- Put your datastore's key here, whatever it is.
This didn’t work for me. In case you want my datastore script here:
local plrs = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local saver = dataStoreService:GetDataStore("SaveLeaderstats")
plrs.PlayerAdded:Connect(function(player:Player) -- Load data
local Data = nil
local success, errormessage = pcall(function()
Data = saver:GetAsync(tostring(player.UserId))
end)
if success then
if Data then
for i,v in pairs(Data) do
player:WaitForChild("leaderstats"):WaitForChild(i).Value = v
end
end
else
error(errormessage)
end
end)
local function Save(player:Player) -- Save the player data
local SavedData = {}
for _, v in pairs(player:WaitForChild("leaderstats"):GetChildren()) do
SavedData[v.Name] = v.Value
end
local success, errormessage = pcall(function()
saver:SetAsync(tostring(player.UserId),SavedData)
end)
if not success then
error(errormessage)
end
end
plrs.PlayerRemoving:Connect(Save)
game:BindToClose(function()
for _,v in pairs(plrs:GetPlayers()) do
Save(v)
end
end)
The coin system works like a collection system. For example I have to walk around with a slow WalkSpeed to get more coins. The exploiter could make or set their WalkSpeed to >16
If you’re trying to remove a specific person, this should help you. Run this in the Developer Console.
local dataStoreService = game:GetService("DataStoreService")
local saver = dataStoreService:GetDataStore("SaveLeaderstats")
local player = "player name here"
local id = game.Players:GetUserIdFromNameAsync(player)
saver:RemoveAsync(id)
This didn’t work. I tried running it in the Developer Console, and there were no errors. I tried rejoining to see if my data reset when I rejoined but it didn’t.
I meant run it on Roblox Studio. If you run it on yourself while in a server, it’ll delete your data but resave it when you leave the server. Use it on your target player or run it on Roblox Studio in the Command Bar.
Still didn’t work. I ran it in the command line with this:
local dataStoreService = game:GetService("DataStoreService")
local saver = dataStoreService:GetDataStore("SaveLeaderstats")
local player = "Emeryund"
local id = game.Players:GetUserIdFromNameAsync(player)
saver:RemoveAsync(id)
I tried publishing the game and it didn’t work either. I also tried rejoining, didn’t work.
Just to clarify, you ran it in the command line on ROBLOX Studio while NOT playtesting right?
If you’re targeting a specific player (other than yourself), I am confident that it should’ve removed their data.
Maybe, although I don’t think this can cause it, but it could be because you saved the Key as a string, so you can try converting to a string instead:
local dataStoreService = game:GetService("DataStoreService")
local saver = dataStoreService:GetDataStore("SaveLeaderstats")
local player = "Emeryund"
local id = game.Players:GetUserIdFromNameAsync(player)
saver:RemoveAsync(tostring(id))