Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make lights flash in random sequence?

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

✓ Accepted answer

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

3 comments

0

I put that into the script replacing the other one and it does not seem to work.

0

Thanks for that! Works great! :D

0

No prob, happy to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.