Player don't be in the leaderboard

I got a script where it shows the top player with most survives:

local ds = DataStore:GetDataStore("MostWinsGlobalStats")
game.Players.ChildAdded:connect(function(player)
	wait(5)
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		local Survivals = leaderstats:FindFirstChild("Survivals")
		if Survivals then
			local laststats = ds:GetAsync("MostSurvivals") or 0
			local lastname = ds:GetAsync("UserName") or "No Stats yet"
			if Survivals.Value >= laststats then
				ds:SetAsync("MostSurvivals",Survivals.Value)
				ds:SetAsync("UserName",player.Name)
			end
			Survivals.Changed:connect(function()
				local leaderstats = player:FindFirstChild("leaderstats")
				if leaderstats then
					local Survivals = leaderstats:FindFirstChild("Survivals")
					if Survivals then
						local laststats = ds:GetAsync("MostSurvivals") or 0
						local lastname = ds:GetAsync("UserName") or "No Stats yet"
						if Survivals.Value >= laststats then
							ds:SetAsync("MostSurvivals",Survivals.Value)
							ds:SetAsync("UserName",player.Name)
						end
					end
				end
			end)
		end
	end
end)

while true do
	game.Lighting.WithMostWins.Value = ds:GetAsync("UserName") or "No Stats yet"
	game.Lighting.MostWInsValue.Value = ds:GetAsync("MostSurvivals") or 0
	wait(1)
end

But sometimes i want to test stuff of high survivals value (Rewards) and maybe i will get on top #1 from getting those stats. So i want to add a line code that if there’s a player with the highest survivals, i can write in that code that he cant be at the leaderboard. I hope you can help me, thanks!

Basically, you want to hide the player with most survivals from leaderboard?
If you do, I think that before this long code you should put an if statement, and if the player doesn’t have the most survivals, code will be executed.

But how do i achieve it? cause i know this is going to use an if statement but what i must write?

As I can see, some “leaderstats” object is inserted into player when they join the game. Could you please show me the hierarchy of that object?

You would add it right below the wait(5) and something like

if player.UserId == playerID then -- add your userid where it says 'playerID'
else
-- Your code here
end

Looks like he’s trying to hide himself from the leaderboards so he isn’t the #1 player on leaderboards while he’s testing features

2 Likes

Sorry for being completely off-topic here, but your current code is a large mess and you’re going to experience some major data throttling. Keep in mind DataStore Limitations when working with DataStores: you don’t have the luxury to make all the calls in the world. Points of error:

  • Using two GetAsync requests per 1 second
  • Using DataStores at all with a Changed event
  • Two GetAsync requests every change and initial setup
  • Two SetAsync requests every time the new value is greater than the previous

As for your actual question, you just need to omit the top player from whatever logic your code is running from. So if you have an iterative loop over top players, skip the first index by doing nothing for it. I don’t know your current implementation (or if you have one at all), so it’s hard to determine an exact way in your scenario to omit the first ranking player.

So, right now i cant test with two players, my question is that adding that statement i will not appear in the leaderboard instantly?

cause i can see in the leaderboard that im still in top 1