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

How to make lights flash in random sequence?

Asked by 9 years ago

Hi,

I have built an event hall and have all working lights and sounds etc. What I want to know is how do I get my lights to flash in a RANDOM sequence. So like when you are at a concert and fast paced music is on you have all the flashing lights How do I get that into a script?

Here is the script were the lights just turn on and pressed, and when pressed again they turn off.

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)

How would I turn this script so that the lights flash in a RANDOM sequence?

Thanks Kieran

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

If I'm understanding this right, you just want a random light to flick on and then off repeatedly? Anyways, if that is the case then you could use this:

On=false
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()
    if On==true then --Checks if the lights are flashing or not
        On=false
        for i=1,#lp do --Goes through all the lights and turns them off
            lp[i].Enabled=false
        end
    elseif On==false then --^Same
        On=true
        while On==true do
            LightNum=math.random(1,#lp) --Chooses a random light from the table
            lp[LightNum].Enabled=true  --Finds which light was chosen from the table and turns it on
            wait(.2)--Change this to however long you want the wait time to be
            lp[LightNum].Enabled=false
        end
    end
end

btn.MouseClick:connect(onClick)

This should work. If you have any questions, please leave a comment below :P -Sorry about it not working that first time. I had a few errors I fixed. I tested and it works now

0
I put that into the script replacing the other one and it does not seem to work. kieranm9090 49 — 9y
0
Thanks for that! Works great! :D kieranm9090 49 — 9y
0
No prob, happy to help! dyler3 1510 — 9y
Ad

Answer this question