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

Help with click detector? Solved.

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)

3 comments

0

What are you trying to do? Make it just print "Clicked on", "Clicked off"?

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)

0

Ok.

1 answer

✓ Accepted answer

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)

4 comments

0

A few slight errors but i fixed it the script works thank you :).

0

Can you mark this answer as accepted please? It helps me out.

0

yeah sorry

0

Thanks.

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