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
9 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)

button = script.Parent
cl = Instance.new("ClickDetector",button)

clicked = false

button.ClickDetector.MouseClick:connect(function()
    if clicked == false then
        clicked = true
        print("Clicked on")
        print("Clciked off") --having trouble here 
        clicked = false

    end

end)
0
What are you trying to do? Make it just print "Clicked on", "Clicked off"? bobafett3544 198 — 9y
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 — 9y
0
Ok. bobafett3544 198 — 9y

1 answer

Log in to vote
-1
Answered by 9 years ago

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

local button = script.Parent
local cl = Instance.new("ClickDetector", button)

local clicked = false

cl.MouseClick:connect(function()
if not clicked then
clicked = true
print"Clicked on."
elseif  clicked then
clicked = false
print"Clicked off."
end
end)
0
A few slight errors but i fixed it the script works thank you :). Damo999 182 — 9y
0
Can you mark this answer as accepted please? It helps me out. bobafett3544 198 — 9y
0
yeah sorry Damo999 182 — 9y
0
Thanks. bobafett3544 198 — 9y
Ad

Answer this question