Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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)
0
Thanks! :) AudreyJeanx 55 — 10y
Ad

Answer this question