How to stop an auto clicker?

Hey, I was wondering how I could stop someone from using an auto clicker in my game?

I tried this, it didn’t work at all.

local btn = script.Parent
local chicken = game.ServerStorage.Beans
local holding = false
local canhold = true
btn.MouseButton1Down:Connect(function()
	holding = true
	while holding do
		if canhold == true then
			wait(0.5)
			chicken:Clone().Parent = game.Workspace
		end
		btn.MouseButton1Up:Connect(function()
			holding = false
			canhold = false
			wait(0.5)
			canhold = true
		end)
	end
end)

Use debounce.

It don’t stop auto clicker but prevent of it click to fast

You could do something like this as suggested above with a debounce:

local debounce = false
local cooldownTime = 0.1
local button = script.Parent
local chicken = game.ServerStorage.Beans

button.MouseButton1Click:Connect(function()
    if not debounce then
        local clone = chicken:Clone()
        clone.Parent = game.Workspace
        wait(cooldownTime)
        debounce = false
    end
end)

This code will clone the model into the workspace whenever the button is clicked. However, if the button is clicked to frequently (under the amount of cooldown time), the chicken will not be cloned.

You might want to use the new task.wait instead of the normal wait, though.

Well, I already tried something really close to that but it didn’t work, could you maybe show me how to use this method while mixed into my model cloning script. I can never seem to put things in the right order.

I can try to help, but I don’t know exactly what you are trying to do. It looks like you are cloning a model to the workspace repeatedly as a player holds the button, but there is a wait time in between. What do you intend for the button to do when clicked/held?

So… What exactly are you trying to do. Because I assume btn is a TextButton since you’re trying to use MouseButton1Down and MouseButton1Up. But you’re trying to access game.ServerStorage, from the client which you can’t do.

While the player holds down the button, every 0.5 seconds a chicken is cloned

local btn = script.Parent
local chicken = game.ServerStorage.Beans
local holding = false
btn.MouseButton1Down:Connect(function()
	holding = true
	while holding do
			wait(0.5)
			chicken:Clone().Parent = game.Workspace
		end
		btn.MouseButton1Up:Connect(function()
			holding = false
		end)
	end
end)

this would error
too many end’s

Sorry I don’t know what that means.

I just changed your code a little and tested this and it works.

local btn = script.Parent
local chicken = game.ReplicatedStorage.Beans
local holding = false
local canhold = true

btn.MouseButton1Down:Connect(function()
	holding = true
	local con;
	con = btn.MouseButton1Up:Connect(function()
		holding = false
		con:Disconnect();
	end)
end)

local waitTime = 0.5;
local waited = 0;

game:GetService("RunService").Heartbeat:Connect(function(dt)
	if holding then
		waited += dt;
		if waited >= waitTime then
			chicken:Clone().Parent = workspace;
			waited = 0;
		end;
	end;
end);

As I said before, you can’t access ServerStorage from the Client, nor can you access user input from the server. So you’re best off firing a remote to the server from the client when they should clone an object so that all players will see it.

1 Like

Try something like this? You’ve almost got a working debounce system but there were some issues/fixes that I pointed out in comments

local btn = script.Parent
local chicken = game.ServerStorage.Beans
local holding = false
local canhold = true
btn.MouseButton1Down:Connect(function()
	if holding then return end -- If we are already holding, stop
	holding = true
	while holding do
		if canhold == true then
			wait(0.5)
			chicken:Clone().Parent = game.Workspace
		end
	end
end)
btn.MouseButton1Up:Connect(function() -- move this outside of the first button1down
	holding = false
	if canhold == false then return end -- don't run this timer more than needed
	canhold = false
	wait(0.5)
	canhold = true
end)
1 Like

I mean you too many end ’s in your code, so it would error

you have four in total, you only need three

Here’s the proper way to do something like this so all the chickens show up to every player

--Client
local btn = script.Parent
local chicken = game.ReplicatedStorage.RemoteEvent
local holding = false

btn.MouseButton1Down:Connect(function()
	holding = true
	local con;
	con = btn.MouseButton1Up:Connect(function()
		holding = false
		con:Disconnect();
	end)
end)

local waitTime = 0.5;
local waited = 0;

game:GetService("RunService").Heartbeat:Connect(function(dt)
	if holding then
		waited += dt;
		if waited >= waitTime then
			chicken:FireServer();
			waited = 0;
		end;
	end;
end);
--Server
local event = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent");

local debounce = {};

event.OnServerEvent:Connect(function(player)
	if not debounce[player] then debounce[player] = tick() - 0.5; end;
	if (tick() - debounce[player]) < 0.5 then return; end;
	debounce[player] = tick();
	game:GetService("ServerStorage"):FindFirstChild("Beans"):Clone().Parent = workspace;
end);

Note: Security wise though, you should be checking on the server when a player can spawn a chicken so that exploiters can’t just constantly fire your remote.

Edit: Added basic server security.

1 Like

JEEZ! So many options, I tried the first script I saw and I think it worked 100% well. @MrLonely1221, Thank you.

2 Likes

I figured out later that @MrLonely1221’s script was not working, but @Brick_man’s was. Thank you all for your help.

How wasn’t it working? Because I tested my script many times and it worked perfectly fine.

Do you mind explaining what didn’t work about it?

If you use the second one I posted, that will secure you from exploiters as well as it handles the debounce on the server.

I would just check if the player has an abnormal CPS (like 100+), and just kick/ban them.

we’ll it worked for the most part but I think it interfered with something else. The button kind of acted as a toggle on/off. It worked earlier, and I know it was probably my fault it is not working now. But I didn’t understand some of it so instead of editing it, I used a different script. But when it worked it worked like a charm. I just think that another one of my scripts must of interfered with it or something.

When I was testing it, when I held it it kept going, and when I clicked once it only did it once, then once again when I clicked the next time.

Here’s my suggestion: :sunglasses:

  1. set health regen to a normal human mouse-clicking speed. eg: 3 taps a second = 3 regen a second.
  2. 1 tap deals 1 damage, something low like 25 health.
  3. turn OFF the health bar and damage indicator.
  4. when they die, give the message “Don’t overdo it, OK?”

Edit to add: create a “leaderboard of shame” for most self-inflicted deaths