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

How to turn off multiple lights at once?

Asked by 3 years ago
Edited 3 years ago

I want to blink then turn off all the lights when you touch a part on the floor.

This is what the workspace looks like for a better understanding

Model
    Script
    Lights
        Part
            SpotLight
        Part
            SpotLight
    Hit (The part that you touch)

This is the script to turn the lights off

local part = script.Parent
local Light = script.Parent.Lights:GetDescendants("SpotLight")
local hit = script.Parent.Hit




local function onPartTouched(hit)
    hit.CanTouch = false
    Light.Enabled = false
    wait(.2)
    Light.Enabled = true
    wait(.1)
    Light.Enabled = false
    wait(.2)
    Light.Enabled = true
    wait(.2)
    Light.Enabled = false
end

hit.Touched:Connect(onPartTouched)
0
yeah, its better to use a for loop in the case JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
BiIinear 104
3 years ago

Use a 'for loop'.

This function turns all lights on/off at once.

local function lights(bool)

    for _, v in pairs(Light) do

        v.Enabled = bool
    end
end

Then, you can call this function in onPartTouched() :

lights(false)
wait(.2)
lights(true)
wait(.1)
lights(false)
wait(.2)
lights(true)
wait(.2)
lights(false)
Ad

Answer this question