How could I remove certain player from global leaderboard?

Hey! So I’m trying to remove a certain player from my global leaderboard, I erased their Data and everything but their name is still on the leaderboard. This is a big problem since if anyone cheats or anything, I won’t be able to delete their Data from the global leaderboard.

The script (isn’t made by me):

local StatsName = "Coins" 
local MaxItems = 100 
local MinValueDisplay = 1 
local MaxValueDisplay = 10e15 
local UpdateEvery = 60 

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = script.Parent
local Sample = script.Sample
local List = SurfaceGui.Frame.List
local ItemsFrame = List.ListContent.Items

local function GetItems()
	local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
	local TopPage = Data:GetCurrentPage()
	
	ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false
	
	for i, v in ipairs(TopPage) do
		local UserId = v.key
		local Value = v.value
		local Username = "[Not Available]"
		local Color = Color3.fromRGB(38, 50, 56)
		
		if i  <= 3 then
			local npc = workspace:FindFirstChild(i)
			if npc then
				npc.UserId.Value = UserId
			end
		end
		
		
		local Success, Error = pcall(function()
			Username = game.Players:GetNameFromUserIdAsync(UserId)
			
		end)
		
		if i == 1 then
			Color = Color3.fromRGB(255, 215, 0)
			
		elseif i == 2 then
			Color = Color3.fromRGB(192, 192, 192)
		elseif i == 3 then
			Color = Color3.fromRGB(205, 127, 50)
		end
		
		local Item = Sample:Clone()
		Item.Name = Username
		Item.LayoutOrder = i
		Item.Values.Number.TextColor3 = Color
		Item.Values.Number.Text = i
		Item.Values.Username.Text = Username
		Item.Values.Value.Text = Value
		Item.Parent = ItemsFrame
	end
end

while true do
	for i, v in pairs(game.Players:GetPlayers()) do
		local Stats = v.leaderstats:WaitForChild(StatsName).Value
		if Stats then
			pcall(function()
				DataStore:UpdateAsync(v.UserId, function(Value)
					return tonumber(Stats)
				end)
			end)
		end
	end
	
	for i, v in pairs(ItemsFrame:GetChildren()) do
		if v:IsA("ImageLabel") then
			v:Destroy()
		end
	end
	
	GetItems()
	
	wait()
	List.ListContent.GuideTopBar.Value.Text = StatsName
	List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
	wait(UpdateEvery)
end

Any help is appreciated! :slight_smile:

Can’t you just do DataStore:SetAsync(PlayersKey, nil) to reset their data?

Where would I write that in tho?

You can quite literally write that in the console of studio or in game or just run it once in a script.

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)

DataStore:SetAsync(PlayersKey, nil)  -- change PlayersKey to the userId of the player you want to data reset

I get a attempt to concatenate string with nil error.

I forgot that you had a separate variable called StatsName when you define your Datastore. Just change it to:

local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_Coins")

To elaborate on what @Ze_tsu said, you might want to consider making a command you can use in game, so you can do it on sight (be mindful of :SetAsync limits though).

Got another error.

As relatch showed above ^

First argument is a string. Put it in " ".

relatch deleted the response, I have no idea what the error means… :confused:

Like so:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_Coins")

DataStore:SetAsync(1635557081, 0)

Or you could also use :RemoveAsync() and do the same thing:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_Coins")

DataStore:RemoveAsync(1635557081)
7 Likes

Oh phew! Tysm!! This was a huge pain for me recently. :pray:

1 Like

I think also talking about exploits, in one plane crash survival, someone was auto getting Survived (a point awarded whenever you survived), and while they unfortunately and shamelessly boosted their Survival points (as an alt) I think adding a debounce would also help.

But as other people said, remove the obvious exploiters from the leaderboard and add a debounce for a currency.

For example, back to the plane crash survival game, a plane goes around 120 seconds, so I’ll said if they get more than 1 under the time of 100 seconds, block it (either by removing it or making them unable to add anything).

No problem! You should probably do what @System502 suggested and make a chat command (or UI) so you can just reset players data in game by doing :ResetData Ze_tsu, etc. Also as he mentioned, remember to stay within rate limits!

Goodluck with your projects!

2 Likes