FIRST ERROR Looking at your script, your random number only generates once meaning that it will have the same random number for every time the while loop ran the code. To counter this, you have to make the random inside of the while loop.
SECOND ERROR After re-reading your code I also found that once the code went into the second while loop of changing the light bulbs the code would get stuck in that code forever. Meaning, it would repeat this code and wouldn’t run anything else until it broke free from the loop. To counter this either delete the while loop and use a for loop to run the light pattern a few times or add a break
once the pattern is done.
THIRD ERROR I think you made a mistake because on line 48 there is an end
yet it’s not really ending anything. This will error your code. You probably forgot to add the while true do
.
Here is some example code:
while wait(1) do
local RandomNumber = math.random(1,2)
if RandomNumber == 1 then
print("First One")
elseif RandomNumber == 2 then
print("Second One")
end
end
If you were to read the output it would put something similar to this:
First One (x2)
Second One
First One
Second One
First One (x3)
Second One (x2)
(You get the point).
So, in your code, instead of putting print("First One")
or print("Second One")
you would put your changing lightbulb script.
To Sum It All Up
Your script only generated a random number once meaning, in your while loop it would repeat the same light bulb pattern every time. So as I’ve said previously, you need to make the random number in the while loop so that way it generates a new number every time a new light pattern is needed.
Also, instead of having while loops inside the pattern you would use a for loop to run the pattern your desired amount of times.
Your code would probably look something like this:
-- Put your lighting variables here
while true do
local RandomNumber = math.random(1,2)
if RandomNumber == 1 then
-- this loop would run the code howmanytimes you want
for numberoftime = 1, HOWmanyTIMES, 1 do
-- Your lightbulb pattern here
end
elseif RandomNumber == 2 then
-- this loop would run the code howevertimes you want
for numberoftime = 1, HOWmanyTIMES, 1 do
-- Your lightbulb pattern here
end
end
end