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 5 years ago

This is a script inside a ColorCorrection in lighting

while true do
local color = math.random(1,4)
if color == 1 then
    script.Parent.Brightness = -0.05
    wait(3)
    print("1")
else
    if color == 2 then
        script.Parent.Brightness = -1
        wait(0.2)
        script.Parent.Brightness = -0.05
        wait(1)
        print("2")
    else


        if color == 3 then
        script.Parent.Brightness = -1
        wait(0.2)
        script.Parent.Brightness = -0.05
        wait(0.1)
        script.Parent.Brightness = -1
        wait(0.2)
        script.Parent.Brightness = -0.05
        wait(4)
            print("3")

            if color == 4 then
    script.Parent.Brightness = -0.05
    wait(3)
                print("4")

            end
        end
    end
end
wait(1)
end

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 — 5y
0
You only put if, rather than elseif. elseif sorts multiple possible outcomes, if only sorts 1. Professor_Hew 10 — 5y

2 answers

Log in to vote
1
Answered by
sheepposu 561 Moderation Voter
5 years ago
Edited 5 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

local loop = 1
local lighting = script.Parent.Parent.Lighting

while loop == 1 do
    local color = math.random(1,4)
    if color == 1 then
        lighting.Brightness = 0.05
        wait(3)
        print("1")
    elseif color == 2 then
        lighting.Brightness = 1
        wait(0.2)
        lighting.Brightness = 0.05
        wait(1)
        print("2")
    elseif color == 3 then
        lighting.Brightness = 1
        wait(0.2)
        lighting.Brightness = 0.05
        wait(0.1)
        lighting.Brightness = 1
        wait(0.2)
        lighting.Brightness = 0.05
        wait(4)
        print("3")
    elseif color == 4 then
        lighting.Brightness = 1
        wait(0.2)
        lighting.Brightness = 0.05
        wait(0.1)
        lighting.Brightness = 1
        wait(0.2)
        lighting.Brightness = 0.05
        wait(4)
        print("4")
    end
    wait(1)
end
Ad
Log in to vote
0
Answered by 5 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:

while true do
local color = math.random(1,4)
if color == 1 then
    script.Parent.Brightness = -0.05
    wait(3)
    print("1")
    elseif color == 2 then
        script.Parent.Brightness = -1
        wait(0.2)
        script.Parent.Brightness = -0.05
        wait(1)
        print("2")
    elseif color == 3 then
        script.Parent.Brightness = -1
        wait(0.2)
        script.Parent.Brightness = -0.05
        wait(0.1)
        script.Parent.Brightness = -1
        wait(0.2)
        script.Parent.Brightness = -0.05
        wait(4)
        print("3")
     elseif color == 4 then
        script.Parent.Brightness = -0.05
        wait(3)
    print("4")
end
wait(1)
end
0
There is no error in output, its just not working barrettr500 53 — 5y

Answer this question