Hey guys i have a script which prints turned on how would i make it to where it will print turned off when i click it again here is the code i can't figure it out.
(When i click it i want it to print clicked on and when i click it a second time i want it to say clicked off)
01 | button = script.Parent |
02 | cl = Instance.new( "ClickDetector" ,button) |
03 |
04 | clicked = false |
05 |
06 | button.ClickDetector.MouseClick:connect( function () |
07 | if clicked = = false then |
08 | clicked = true |
09 | print ( "Clicked on" ) |
10 | print ( "Clciked off" ) --having trouble here |
11 | clicked = false |
12 |
13 | end |
14 |
15 | end ) |
You didn't add anything to check if "clicked" was off.
01 | local button = script.Parent |
02 | local cl = Instance.new( "ClickDetector" , button) |
03 |
04 | local clicked = false |
05 |
06 | cl.MouseClick:connect( function () |
07 | if not clicked then |
08 | clicked = true |
09 | print "Clicked on." |
10 | elseif clicked then |
11 | clicked = false |
12 | print "Clicked off." |
13 | end |
14 | end ) |