Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make an On/Off Button for an Auto Clicker?

I am trying to make it so when a player clicks the On button it gives then 1 click every 0.5 seconds. But if they click the off button, it stops.

Here's my code: When I test this, it works when I press On, but it doesn't stop when I press off.

local GUI = script.Parent
local onButton = GUI.OnButton
local offButton = GUI.OffButton
local plr = game.Players.LocalPlayer

while onButton.MouseButton1Click do
	while wait() do
		local plrClicks = plr.leaderstats.Clicks
		plrClicks.Value = plrClicks.Value + 1
		if offButton.MouseButton1Click then
			break
		else
		--contine loop?
		end
	end
end



If you have any idea how to fix this, please help!

2 comments

0

You haven't connected any function to offButton.MouseButton1Click, it isn't a bool, it's an event.

0

What do I do to fix that?

1 answer

I'm not the best at scripting, but maybe this'll work

local GUI = script.Parent
local onButton = GUI.OnButton
local offButton = GUI.OffButton
local plr = game.Players.LocalPlayer
local plrClicks = plr.leaderstats.Clicks
local adding = 1

local function Off()
	adding = 0
end

local function On()
	while wait() do
		plrClicks.Value += adding
	end
end

onButton.MouseButton1Click:Connect(On) --When On button is clicked, start adding
offButton.MouseButton1Click:Connect(Off) --When Off button is clicked, change adding to 0

2 comments

0

I tried this and nothing happened when I clicked either buttons. I made it so it printed "ON" when it was running and printed "OFF" when it was not. It printed On,Off,On,Off over and over again when I tested it.

0

The repeated on/off is because of the while loop, lemme edit my answer

This discussion is preserved as it was. New answers, comments, and votes are closed.