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

How can I make an On / Off button GUI?

Hello guys sorry for bother (again.)

For example I want that, when you click on a button in the GUI (let's call the *"On / Off * button) That when I click on it the first time, repeat the script that I want infinitely and when I click it for second Once to the button, stop running the script that was running infinitely.

I think it's done with "While true do" loop but it does not work for me.

Any ideas? :(

1 comment

0

button gets clicked -> someBool = false...then your loop: while someBool = true -> will stop executing when the button is pressed

1 answer

✓ Accepted answer
local BoolValue = false

function Click(mouse)

if BoolValue == false then
	BoolValue = true
	print (BoolValue)
	script.Parent.Text = "On"
else
	BoolValue = false
	print (BoolValue)
script.Parent.Text = "Off"
end
end

script.Parent.MouseButton1Down:Connect(Click)

wait ()
while true do
	wait ()
	if BoolValue == true then
		--code here
	end
end

put this script in a local script in a text button

6 comments

0

Thank you so much dude, i really appreciate your help!

0

np

0

i mean u helped him, but this a help site, not a request site for users to use. perhaps explain the code to him so it would help him understand why? Also, use :Connect instead of :connect

1

-1 for not explaining.

0

Yeah im gonna work on this :)

0

Would be faster if you used !BoolValue to make it faster.

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