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

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

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

2 comments

0

You only put if, rather than elseif. elseif sorts multiple possible outcomes, if only sorts 1.

0

You only put if, rather than elseif. elseif sorts multiple possible outcomes, if only sorts 1.

2 answers

✓ Accepted answer

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

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

1 comment

0

There is no error in output, its just not working

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