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

Click Dector Lights

I have made a police bar with working lights now i need a script that can turn of and on the lights with a button the the back of the lights. Please help me .

2 answers

✓ Accepted answer
script.Parent.MouseDetector.MouseClick:connect(function()  --Use the MouseClick event on click detectors to detect when the part is clicked on
	script.Parent.SpotLight.Enabled=not script.Parent.SpotLight.Enabled --This flips the SpotLight's enabled property, so if off clicking on it will turn it on vice versa
end)  --ending the function

Here's the script... It's kinda long, because I was too tired to think of a faster one. Basically, it just checks if the light is on then turns it off and vice versa.

Light = script.Parent.SpotLight

script.Parent.MouseDetector.MouseClick:connect(function()
	script.Parent.SpotLight
	if Light.Enabled then
		Light.Enabled = false
	else
		Light.Enabled = true
	end
end)

Well, enjoy. I hope it works, because I hardly use ClickDetectors. I use SurfaceGui's.

  • Kratos232

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