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

Help with script to do strobe lighting?

Asked by 10 years ago

Hi,

So I have this script. It turns all the lights on and off when I click it on and off. Now I want it to randomly strobe the lights. I press the button and it does random strobe lights but not at the same time, different times to make the show effect. Then when I press the button there it all turns off. The button turns RED when on The button turns GREY when off.

Please help to make it work for this script.

local P = script.Parent.Parent
local LP1 = P.SpotLight12.Light.SpotLight
local LP2 = P.SpotLight11.Light.SpotLight
local LP3 = P.SpotLight10.Light.SpotLight
local LP4 = P.SpotLight9.Light.SpotLight
local LP5 = P.SpotLight8.Light.SpotLight
local LP6 = P.SpotLight7.Light.SpotLight
local LP7 = P.SpotLight6.Light.SpotLight
local LP8 = P.SpotLight5.Light.SpotLight
local LP9 = P.SpotLight4.Light.SpotLight
local LP10 = P.SpotLight3.Light.SpotLight
local LP11 = P.SpotLight2.Light.SpotLight
local LP12 = P.SpotLight1.Light.SpotLight
lp = {LP1, LP2, LP3, LP4, LP5, LP6, LP7, LP8, LP9, LP10, LP11, LP12}
btn = script.Parent.ClickDetector

function onClick()
    for i, v in pairs(lp) do
        v.Enabled = not v.Enabled
    end
end

btn.MouseClick:connect(onClick)

Thanks Kieran

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

We add a loop in conjunction with the click.

Instead of changing the enabled state of the lights directly in the click, we just set whether or not the lights are 'on' (strobing) or 'off' (disabled).

A loop works constantly; if the lights are 'off' is disables them (false) and if they are 'on' (strobing) then it invets them (Enabled = not Enabled)


local lightsOn = false; function off() for i, v in pairs(lp) do v.Enabled = false; end end function onClick() -- Instead of changing lights directly, -- we just change one variable meaning "on" -- of "off" (where "on" actually means flicker) lightsOn = not lightsOn; if not lightsOn then -- If we have something like a 1 second delay, -- the loop can't turn the lights off until the -- next delay. -- That would make it appear unresponsive, -- so we directly turn it off here. off(); end end btn.MouseClick:connect(onClick); while wait(0.5) do -- Just work every half second if lightsOn then -- If the light switch is enabled, flicker for i, v in pairs(lp) do v.Enabled = not v.Enabled; end else -- If the light switch is set to off, -- keep all the lights off off(); end end

Note that lights flashing at more than 1Hz can do damage to people especially with epilepsy

0
Ok thanks for that. How do I change the frequency so that I make sure it does not go below the 1Hz. kieranm9090 49 — 10y
0
It's just a note. If the `wait` time is more than a second then there's not so much of a concern. If you want it to be faster than that just making a notice in the description / in a GUI prior would be enough (or not at all since few people do  make considerations for epilepsy /  strobing lights) BlueTaslem 18071 — 10y
Ad

Answer this question