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
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)
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.
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 …
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)
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.