How to reset someone's stats if they aren't in the server [SOLVED]

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.

1 Like

what do you mean, like just wiping their data when they leave or?

local datastore = game:GetService("DataStoreService"):GetDataStore("DataStoreName")

game.Players.PlayerRemoving:Connect(function(player)
    datastore:RemoveAsync(keygoeshere)
end)
1 Like

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

I mean resetting someones points stat if they aren’t in the game.

Just remove their key from the datastore as mentioned

I’ll try this out now with your method. And yes, I’m trying to reset someones data without having to be in a server with them

I feel like you should make your coin system more secured in the first place

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

There are anticheats to counter it tho, unless your game allows over 16 walkspeed

I mean you can make anticheats*

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)

2 Likes

Yes, I’m looking for something like this. I’ll run this in the Developer Console now.

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.

1 Like

Oh. Thanks for confirming that. I will try this instead then.

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.

Forgot to mention, I did use the ; to concatenate the line.

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))
1 Like

I didn’t run it while playtesting. I will try converting the key to a string.