Ban if leaderstats are too high

Hello, my name is Rizzy.

I need help on creating a script where the player gets banned if they get a certain leaderstat that I don’t want them to get to. Any help would be great.

BAD IDEA a save glitch could happen and there leaderstats will sometimes go off the charts

I think it would be better just to limit the stats you want rather than banning the player. If no one could have more than 100 of cash, check how much cash they have, and if it’s higher just set it to the limit.

What do you mean?

You mean when the player get’s a specific number on a value inside the leaderboard, it gets banned?

Well, it’s pretty easy to check if the stats are too high. Here’s a little code example:

local ValueIfToHigh = 100
while wait() do
	for i, v in ipairs(game.Players:GetPlayers()) do
		if v.leaderstats.IntValueHere.Value > ValueIfToHigh then
			v:Kick()
		end
	end
end
2 Likes

2 things. I know your name is blueloops, so you used a loop. But that is not a very good method for performance. You should rather do a Changed event:

v.leaderstats.IntValueHere.Changed:Connect(newValue)
    if newValue > ValueIfToHigh then
		v:Kick()
	end
end)

Also both of these examples just kick and do not ban.

1 Like

Yeah this worked perfectly for me. How would I use RemoveAsync to remove those leaderstats from the leaderboard?

Bad idea but you could make a ban datastore and function, function sets the ban value to true, saves it and kicks them

Something like

local function Ban(p)

	local banVal = p.Stats:FindFirstChild("Banned")-- a value inside the player identifying if they are or arent banned

	if banVal then

		banVal.Value = true
		local DataToSave = {}
		DataToSave[banVal.Name] = banVal.Value
		BanDataStore:SetAsync(p.UserId, DataToSave)
		p:Kick("You've been banned!\nReason: ???")

	else

		warn("Ban value not found")

	end

end

local MaxValue = 50000 -- change to whatever

-- this would go in where the players given the value
if player.leaderstats.StatName.Value >= MaxValue then
	Ban(player) -- ban would be the function
end

player.leaderstats.StatName.Changed:Connect(function()
	if player.leaderstats.StatName.Value >= MaxValue then
		Ban(player) -- ban would be the function
	end
end)

Something like that