Limit CPS for anti-autoclicker

I’m trying to make a game sort of like Cookie Clicker and:

In my game, using autoclicker is a problem and a big exploit. How could I limit the CPS to 10 without using any debounce/delay between the clicks?

--[ VARIABLES ]--
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local CurrentClicks = 0
local MaxClicks = 10
local TimeUntilClicksReset = 0.2

--[ MAIN ]--
Mouse.Button1Down:Connect(function()
	CurrentClicks += 1
	
	if CurrentClicks > MaxClicks then
		Player:Kick("Autoclicker Detected.")
	end
end)

Mouse.Button1Up:Connect(function()
	spawn(function()
		wait(TimeUntilClicksReset)
		CurrentClicks = 0
	end)
end)

I recommend you put it in StarterCharacter>StarterPlayerScripts

5 Likes

Okay, thanks for this! Really appreciated!

As this is in a local script, exploiters could easily change it to bypass the CPS limit, and instead of using spawn() you should use coroutines.

Okay, here is an updated scirpt:

--[ VARIABLES ]--
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local CurrentClicks = 0
local MaxClicks = 10
local TimeUntilClicksReset = 0.2

--[ MAIN ]--
Mouse.Button1Down:Connect(function()
	CurrentClicks += 1
	
	if CurrentClicks > MaxClicks then
		Player:Kick("Autoclicker Detected.")
	end
end)

Mouse.Button1Up:Connect(function()
	local ResetClicks = coroutine.create(function()
		wait(TimeUntilClicksReset)
		CurrentClicks = 0
	end)
	
	wait(TimeUntilClicksReset)
	coroutine.resume(ResetClicks)
end)
2 Likes

It can still be bypassed by exploiters, I would recommend having the clicks be sent by a remote event and have a server script check for autoclicking.

1 Like

Makes sense. (charsssssssssssssss)

I assume, the server will be handling the event of a click, through a remote event or some internal thing such as .Activated, Add a debounce; This’ll one; make the auto-clicker useless, two; wont cause any not needed scripts on the client, and three; won’t be bypassed by the client.

local playerMutexes = { }

remote.OnServerEvent:Connect(function(player)
  if playerMutexes[player] then
    if tick() - playerMutexes[player] < .05 then
       return player:Kick("Abc, 123")
    end
  end

  playerMutexes[player] = tick()
  
  -- process event.
end)
3 Likes

I created a script similar to what you’re talking about, but of course it has a bug. Btw this is my first post, be critical about how I discuss and ask.

This is my local code:

--[ VARIABLES ]--
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local events = workspace.Events

--[ MAIN ]--
Mouse.Button1Down:Connect(function()
	events.ClickDownServerEvent:FireServer(Mouse)
end)

Mouse.Button1Up:Connect(function()
	events.ClickUpServerEvent:FireServer(Mouse)
end)

This is my server code:

--[ VARIABLES ]--
local Player = game.Players.LocalPlayer
local CurrentClicks = 0
local MaxClicks = 10
local TimeUntilClicksReset = 0.2
local events = workspace.Events


--[ MAIN ]--
events.ClickDownServerEvent.OnServerEvent:Connect(function(Mouse)
	CurrentClicks += 1

	if CurrentClicks > MaxClicks then
		Player:Kick("Autoclicker Detected.")
	end
end)

events.ClickDownServerEvent.OnServerEvent:Connect(function(Mouse)
	local ResetClicks = coroutine.create(function()
		wait(TimeUntilClicksReset)
		CurrentClicks = 0
	end)

	wait(TimeUntilClicksReset)
	coroutine.resume(ResetClicks)
end)

Sorry for updating so late!

2 Likes

Please don’t be mad about me copying you guys I’m just trying to bring your idea to reality.

You’re actually very wrong here. Nothing should be used as it’s a connection, even in a case where it wouldn’t be, if you don’t really need to manage the thread and just need it to run you should use spawn.

And remember to use task.spawn when you do decide using spawn :smile:

Source: Trust me bro
Reason: Spawn has a higher priority than coroutine

game.ReplicatedStorage.ClickRemote:Destroy()

not hard to exploit your check, unless it is the same remote that counts points

I see, although I’m not very educated in task.spawn. I’ll try that.

Wait… If exploiters had access to local scripts, couldn’t they just do the following?

local hackScript = script
 
for _, thing in ipairs(workspace:GetDescendants) do
     if thing.Name == hackScript.Name then continue end
     thing:Destroy
end

And keep repeating this for replicated storage, server storage, server script service, etc.

Also, couldn’t they just keep cloning something a lot like the script itself?

while true do
     script:Clone()
     wait(0.01)
end

The wait() would dodge the script exhaustion system, and could just increase the ping immensely while replicating itself. If an exploiter has that access, I don’t know what to do(until roblox creates the anticheat system)!

10 CPS is low, normal people can get above 10 CPS easily without an autoclicker, some suggestions would be:

  1. Up the CPS Cap
  2. Check if the clicks are constantly in the same location
  3. Check if there is a steady difference in time between clicks.

I haven’t put much though into increasing the CPS cap but now that I think about it, good idea.

Yea that’s a smart idea but if exploiters find about this, they can easily make a python program to move the cursor and/or move their mouse around.

Exploiters can make it so the CPS changes. Also an innocent player might accidentally have a constant CPS and could be banned.

I can’t get 10 cps lol

1 Like

Unfortunately you cannot make this serverside, if the player has really terrible ping then the server will just see 30 cps. That is if you kick them - You can just tell the server to not continue with this remote event if they are clicking too quickly.

I am completely aware of that and yeah, it’s easy to do

No one will have an exact steady CPS. Once again I am aware of the ability to change CPS (and mouse position) with autoclicker but nonetheless it’s still a good idea as it will still cut down the number on rope of the CPS cap.

As for this:

I have nothing to say lol

Sorry but this does not detect auto-clickers efficiently. The proper way to detect auto-clickers is to use tick() to check if there is a coincidence between the delay of clicks which auto-clickers have the same if not similar. You could still have this system run along side it for extra protection.