Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make an On / Off button GUI?

Asked by
C1RAXY 81
6 years ago
Edited 6 years ago

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? :(

0
button gets clicked -> someBool = false...then your loop: while someBool = true -> will stop executing when the button is pressed Vulkarin 581 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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

0
Thank you so much dude, i really appreciate your help! C1RAXY 81 — 6y
0
np MageMasterHD 261 — 6y
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 Lugical 425 — 6y
1
-1 for not explaining. User#19524 175 — 6y
View all comments (2 more)
0
Yeah im gonna work on this :) MageMasterHD 261 — 6y
0
Would be faster if you used `!BoolValue` to make it faster. httpOmqCxpcake 70 — 6y
Ad

Answer this question