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

Math.Random on lighting is not working for some reason?

Asked by 6 years ago

This is a script inside a ColorCorrection in lighting

01while true do
02local color = math.random(1,4)
03if color == 1 then
04    script.Parent.Brightness = -0.05
05    wait(3)
06    print("1")
07else
08    if color == 2 then
09        script.Parent.Brightness = -1
10        wait(0.2)
11        script.Parent.Brightness = -0.05
12        wait(1)
13        print("2")
14    else
15 
View all 38 lines...

To make the screen randomly flash black, not working, nothing in output not even printing

any idea as to what I did wrong? :p

0
You only put if, rather than elseif. elseif sorts multiple possible outcomes, if only sorts 1. Professor_Hew 10 — 6y
0
You only put if, rather than elseif. elseif sorts multiple possible outcomes, if only sorts 1. Professor_Hew 10 — 6y

2 answers

Log in to vote
1
Answered by
sheepposu 561 Moderation Voter
6 years ago
Edited 6 years ago

First off, I edited it using 'elseif'. It is way more organized. Anyways, put this into ServerScriptService. Alos one more thing. You said you're making the lights flash black. If you're doing that you'll need to switch the '0.05's and '1's

01local loop = 1
02local lighting = script.Parent.Parent.Lighting
03 
04while loop == 1 do
05    local color = math.random(1,4)
06    if color == 1 then
07        lighting.Brightness = 0.05
08        wait(3)
09        print("1")
10    elseif color == 2 then
11        lighting.Brightness = 1
12        wait(0.2)
13        lighting.Brightness = 0.05
14        wait(1)
15        print("2")
View all 38 lines...
Ad
Log in to vote
0
Answered by 6 years ago

Your issue is, that you're not supporting us with the Output showing the error. Also, from what i've determined and understanding, you're not using your elseif correctly. Here is what I suggest:

01while true do
02local color = math.random(1,4)
03if color == 1 then
04    script.Parent.Brightness = -0.05
05    wait(3)
06    print("1")
07    elseif color == 2 then
08        script.Parent.Brightness = -1
09        wait(0.2)
10        script.Parent.Brightness = -0.05
11        wait(1)
12        print("2")
13    elseif color == 3 then
14        script.Parent.Brightness = -1
15        wait(0.2)
View all 29 lines...
0
There is no error in output, its just not working barrettr500 53 — 6y

Answer this question