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?
✓ ANSWER ACCEPTED
How do I turn wire a light switch to a pointlight?
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks! :)