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

How do I link a "Light Switch" and make it turn on more than one light?

Asked by 9 years ago

I made a light switch that controls only one light, here is the script used:

switch = script.Parent
light = game.Workspace.LIGHT.PointLight


switch.ClickDetector.MouseClick:connect (function()
    if light.Enabled == false then
        light.Enabled = true
        switch.BrickColor = BrickColor.new("Lime green")

    elseif light.Enabled == true then
        light.Enabled = false
        switch.BrickColor = BrickColor.new("Really red")
    end 
end)

How do I make more than one light turn on but with only using the one light switch? (I need 6 PointLight blocks to turn on with only one light switch on the wall)

1 answer

Log in to vote
1
Answered by 9 years ago

You can put all of the PointLight object parts into a single model and then use a For loop to turn each one on. Here is the For loop that you would need to use:

switch = script.Parent

switch.ClickDetector.MouseClick:connect (function()
    for i, v in pairs(game.Workspace.MODELNAME:GetChildren()) do
        if v.PointLight.Enabled == true then
            v.PointLight.Enabled = false
            switch.BrickColor = BrickColor.new("Really red")
        else
            v.PointLight.Enabled = true
            switch.BrickColor = BrickColor.new("Lime green")
        end
        wait()
    end
end)
0
You would place this inside of the switch object that is being clicked. I have edited this multiple times so you may need to refresh the page to see the most recent version. FearMeIAmLag 1161 — 9y
0
It works! Thank you so much! LitoTech 35 — 9y
0
No problem. It's what the site is for. FearMeIAmLag 1161 — 9y
Ad

Answer this question