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

Help with click detector? Solved.

Asked by
Damo999 182
10 years ago

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)

01button = script.Parent
02cl = Instance.new("ClickDetector",button)
03 
04clicked = false
05 
06button.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 
15end)
0
What are you trying to do? Make it just print "Clicked on", "Clicked off"? bobafett3544 198 — 10y
0
(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) Damo999 182 — 10y
0
Ok. bobafett3544 198 — 10y

1 answer

Log in to vote
-1
Answered by 10 years ago

You didn't add anything to check if "clicked" was off.

01local button = script.Parent
02local cl = Instance.new("ClickDetector", button)
03 
04local clicked = false
05 
06cl.MouseClick:connect(function()
07if not clicked then
08clicked = true
09print"Clicked on."
10elseif  clicked then
11clicked = false
12print"Clicked off."
13end
14end)
0
A few slight errors but i fixed it the script works thank you :). Damo999 182 — 10y
0
Can you mark this answer as accepted please? It helps me out. bobafett3544 198 — 10y
0
yeah sorry Damo999 182 — 10y
0
Thanks. bobafett3544 198 — 10y
Ad

Answer this question