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

How do I turn wire a light switch to a pointlight?

I want to have a little lightswitch that, when you click it, makes the pointlight turn on that is on another part. Is there a way I can do this?

1 answer

✓ Accepted answer

Start by Inserting the Part that you want your switch to be. Insert a ClickDetector object inside this Part and a script to it(not the Detector!)

Use this code to Enable/Disable your light

function onClicked()
	game.Workspace.PartWithPointLight.PointLight.Enabled = true --Or set it to false.
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

You can also have it, so every time you click the "switch" the light will open or if it's already then it will go away.

function onClicked()
	if game.Workspace.PartWithPointLight.PointLight.Enabled == false then
		game.Workspace.PartWithPointLight.PointLight.Enabled = true
	elseif game.Workspace.PartWithPointLight.PointLight.Enabled == true then
		game.Workspace.PartWithPointLight.PointLight.Enabled = false
	end
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 comment

0

Thanks! :)

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