A Button That Repeats A Script Until Its Pressed Again

So i was making a admin gui for a game that im working on and i wanted to create some templates for buttons.
I made something similar in the past but i lost it since i didnt upload it to roblox.
But for some reason everything looks good and the buttons do its just what the script needs to repeat is the problem.

local button = script.Parent.Parent
local enabled = false

button.MouseButton1Down:Connect(function()
	print("Checking If Its Enabled")
	if enabled == false then
		enabled = true
		print("Not Enabled")
	else
		enabled = false
		print("Enabled")
	end
end)


while enabled == 2 do
	--Put your event you want to repeat
	print("Repeating")
	wait(1)
end
1 Like

The while loop is like an if statement. If the following statement is true, then it starts repeating.

You should move the while loop to inside the if statement. I’m on mobile so I cant put a script down so I think you should be able to figure it out yourself.

while enabled == 2 do
	--Put your event you want to repeat
	print("Repeating")
	wait(1)
end

I think this is suppose to say:

while enabled == true do

That was a typo i made fixed after posting this.
Got it to work anyways from @IAmPinleon

Sadly I forgot To Put Wait And My Studio Crashed

1 Like
local button = script.Parent.Parent
local enabled = false

while true do
if enabled = true then
--repeat
end
wait(0.025)
end

button.MouseButton1Down:Connect(function()
if enabled = false then
enabled = true
else
enabled = false
end
end)