AutoClicker error

I’m trying to make a auto clicker for my clicker sim game and when the player clicks the button the value inside the button becomes true and then if he clicks again it becomes false i was trying to fix it for hours didn’t work what happens is when you play it and if you spam the auto clicker it just keeps making a new while loop when it’s meant to stop the second time you click it if you can find out the problem that would be great and much appreciated i will first put the server script below then the local script
server script
game.ReplicatedStorage[“Clicks detection”].GroupAutoClicker.OnServerEvent:Connect(function(player, clicks, clicked)
while clicked do
clicks.Value += 1
wait(1.55)
if not clicked then
break
end
end
end)

local script:
local clickinggui = script.Parent
local localplayer = game.Players.LocalPlayer

local leaderstats = localplayer:FindFirstChild(“leaderstats”)
local Clicks = leaderstats:FindFirstChild(“Clicks”)
local clicked = nil

clickinggui.FreeAutoClick.MouseButton1Click:Connect(function()
if localplayer:IsInGroup(16061187) then

	if clickinggui.FreeAutoClick.Clicked.Value == false then
		clickinggui.FreeAutoClick.Clicked.Value = true
		clicked = true
	elseif clickinggui.FreeAutoClick.Clicked.Value == true then
		clickinggui.FreeAutoClick.Clicked.Value = false
		clicked = false
	end
	game.ReplicatedStorage["Clicks detection"].GroupAutoClicker:FireServer(Clicks ,clicked)
	end

end)

1 Like
ServerScript
task.wait(3)

local autoClickers = {}
local rep = game:GetService("ReplicatedStorage")
local auto = rep:WaitForChild("Clicks detection"):WaitForChild("GroupAutoClicker")

auto.OnServerEvent:Connect(function(player, clicks, clicked)
	if clicked then
		if autoClickers[player] then return end
		autoClickers[player] = true
		   clicks.Value += 1
		   task.wait(1.55)
	else
		autoClickers[player] = nil
	end
end)
LocalScript
task.wait(3)

local clickinggui = script.Parent.Parent
local localplayer = game.Players.LocalPlayer
local clicked = script.Parent:WaitForChild("Clicked") 
local leaderstats = localplayer:FindFirstChild("leaderstats")
local Clicks = leaderstats and leaderstats:FindFirstChild("Clicks")

local rep = game:GetService("ReplicatedStorage")
local auto = rep:WaitForChild("Clicks detection"):WaitForChild("GroupAutoClicker")

if Clicks then
	clickinggui.FreeAutoClick.MouseButton1Click:Connect(function()
	--	if localplayer:IsInGroup(16061187) then
			clicked.Value = not clicked.Value
		auto:FireServer(Clicks, clicked.Value)
	--	end
	end)
end
Leaderstats
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Clicks = Instance.new("IntValue")
	Clicks.Name = "Clicks"
	Clicks.Value = 0
	Clicks.Parent = leaderstats
end)
Structure
StarterGui
  ├── ScreenGui
      ├── FreeAutoClick (TextButton)
          ├── Clicked (BoolValue)
          ├── LocalScript
ReplicatedStorage
  ├── Clicks detection (Folder)
      ├── GroupAutoClicker (RemoteEvent)
ServerScriptService
  ├── ServerScript 
  ├── Leaderstats
2 Likes

Client could pass something else entirely and get the server to increment its value. Just wanted to point it out.

1 Like

I just tried to copy what he had trim it down a bit and get it working. Tested as counting clicks…
Not really sure about the logic here turned out to be more of a have everything defined.

1 Like

wow i never knew that thanks you so much for letting me know ill try to do something with that and see if it works

1 Like

i tried to put if not clicked then return end and it does not seem to work it just keeps running the while loop

1 Like

I have tried using this but ur local script doesn’t have a while loop so i added one and it sadly does not work ill put the script below that i copied from you

local script:
local clickinggui = script.Parent
local localplayer = game.Players.LocalPlayer

local leaderstats = localplayer:FindFirstChild(“leaderstats”)
local Clicks = leaderstats:FindFirstChild(“Clicks”)
local clicked = clickinggui.FreeAutoClick.Clicked

clickinggui.FreeAutoClick.MouseButton1Click:Connect(function()
if localplayer:IsInGroup(16061187) then
clicked.Value = not clicked.Value
game.ReplicatedStorage[“Clicks detection”].GroupAutoClicker:FireServer(Clicks ,clickinggui.FreeAutoClick.Clicked.Value)
end
end)

server script:
local autoClickers = {}
game.ReplicatedStorage[“Clicks detection”].GroupAutoClicker.OnServerEvent:Connect(function(player, clicks, clicked)
if clicked then
if autoClickers[player] then return end
autoClickers[player] = true
while clicked do
clicks.Value += 1
task.wait(1.55)
end
else
autoClickers[player] = nil
end
end)

Odd works fine for me. I do test them before I post. Never really went over your logic as it looked like it would work … There was some concern over the loop so I removed it. Works both ways …

ye but try to click it like 20 time’s then the loop just keep’s going

It worked as many times as I clicked it …

I don’t get why it’s doing all that anyways. Why not just something like this.

task.wait(3)

local rep = game:GetService("ReplicatedStorage")
local auto = rep:WaitForChild("Clicks detection"):WaitForChild("GroupAutoClicker")
local db = true

auto.OnServerEvent:Connect(function(player, clicks, clicked)
	if clicked and db then db = false
		clicks.Value += 1
		task.wait(1.55) --> adjust to what you want
		db = true
	end
end)

nope i tried doing this but it only adds a click once. i want it to keep adding clicks cuzz it’s a autoclicker button

This works as many times as you click it … you must have something else wrong.
Here is my test program …
Clicker.rbxl (61.4 KB)

My friend fixed it for me so ye thank you all for you’er help ill leave the fixed code below if anyone want’s to learn from it
local script:
local clickinggui = script.Parent
local localplayer = game.Players.LocalPlayer

local leaderstats = localplayer:FindFirstChild(“leaderstats”)
local Clicks = leaderstats:FindFirstChild(“Clicks”)
local clicked = clickinggui.FreeAutoClick.Clicked

local AutoEnabled = false

clickinggui.FreeAutoClick.MouseButton1Click:Connect(function()
if not localplayer:IsInGroup(16061187) then

	-- stops autoclicker from running if NOT in group
	return
end

AutoEnabled = not AutoEnabled

if AutoEnabled then
	repeat 

		task.wait(1.75) -- Delay (time between clicks)
		game.ReplicatedStorage["Clicks detection"].normalclick:FireServer(Clicks, Clicks)
		print("clicking")

	until AutoEnabled == false

end

print(AutoEnabled)

end)

server script:
game.ReplicatedStorage[“Clicks detection”].GroupAutoClicker.OnServerEvent:Connect(function(player, clicks, clicked)
if clicked then
clicks.Value += 1
end
end)

As long as your happy with it, great! I don’t like to use spaces in folder names myself … I would have went with ClicksDetection vs “Clicks detection” and I like to define as much as I can up top. I guess it doesn’t really matter. In fact I never use spaces on anything.

yes you’re right i don’t like to use spaces either but i still used why i don’t remember maybe i forgot idk tbh but thanks for you’er help!

1 Like