Lightning Flicker Effect?

Hi, I want to make weather in my game and I’ve been stuck on how to make a good lightning flicker effect. I know about the Lighting’s brightness stuff and other properties to do this, but I’ve been stuck on making a good flicker effect. In real life, when lightning strikes, the light starts out bright. When it flickers, it slowly turns dimmer and also flickers slower. How would I do this? Any help is appreciated, Thanks!

1 Like

Hey BlueBloxBlast! Regarding such, have you tried connecting the lighting to a remote event then getting receiving the event, after such have u tried looping the spot lights enabled status?

To create a flickering effect for the lightning, randomly vary the brightness between two variables, min and max, throughout the lightning’s duration. If you tween both min and max to 0, the flickering will gradually decrease in intensity and eventually stop when it’s no longer visible.

I assume you’re gonna use a Pointlight to create the lighting flicker, in which you would manipulate the property Brightness to achieve this.

This is how I would do it:

local light  = script.Parent.PointLight -- refrence your light here


-- put this function in the event where the lightning strikes

local function strike()
	
	local AmountOfLightRepeating = 0
	
	while true do
		
		light.Brightness = 20
		task.wait(0.03)
		light.Brightness = 1
		task.wait(0.03)
		light.Brightness = 20
		
		
		
		AmountOfLightRepeating += 1
		
		
		
		if AmountOfLightRepeating == 2 then
	
			break
			
			
		end
		
		
	end
	
	
	for i = 20 , 0, -1 do -- use for i loop to do a smooth transition, you can use tween service instead if you like.
		
		task.wait(0.001)
		light.Brightness = i
		
	end
	
end


-- put this function on your lighting event

strike()

So i made a better flicker effect with rng to decide if the light should flicker or not.

local light = script.Parent.PointLight --Or any other type of light just change it to yours.

while task.wait(.25) do
	local rng = math.random(1, 5)
	if rng <= 3 then
		light.Brightness = 8
	else
		light.Brightness = 0
		print("Flicker")
	end
end

:slight_smile: :crazy_face:

By the way i cant recommend using while true do since its very laggy! :wink:

The loop only runs 2 times so I’d say its negligible.

I dont think so, since im almost sure he would use it in more than 1 light… That would maybe result in a minimum performance issue BUT STILL! while.true do is very stinky i suggest using while.task.wait() for better perfomance. :smile:

Try using this script using lerp inside a light instance:

local Light = script.Parent
local LightMax = 3 
local CoolDown = 3

local function Flick()

	local function Lerp(a,b,t)
		return (a + (b - a) * t)
	end

	local RandomBrightness = math.random(1,LightMax)

	for Index = .01, .1, .1 do
		task.wait(.1)
		Light.Brightness = Lerp(LightMax,RandomBrightness,CoolDown)
	end
	
	Flick()
end
Flick()

1 Like