How to make a flickering light in roblox

Okay so in roblox i have been trying to make a flickering light but it doesn't seem work. So i have tried finding what my error in line one is but.. it doesn't seem to work and i can't seem to find it.

while true do
    math.randomseed(tick())
    local Brightness = math.random(0.1 , 1)
    local Light = script.Parent
    local SpotLight = Light.SL
    local RandomPause = (math.random(0.5 , 5))
    wait(RandomPause)
    SpotLight.Brightness = Brightness
    wait (RandomPause)
    SpotLight.Brightness = Brightness
end

asked Oct 28, 2020 at 15:38

How to make a flickering light in roblox

  1. Insert a spotlight into the part

  2. Insert this script into the part:

    local spotlight = game.Workspace.Light.SpotLight
    
    while true do 
    spotLight.Enabled = true
    wait(2)
    spotLight.Enabled = false
    wait(0.1)
    spotLight.Enabled = true
    wait(0.3)
    spotLight.Enabled = false
    wait(0.5)
    
    end
    
    

You can edit the "wait(time)" as you wish to speed up the flickering or slow it down.

answered Nov 23, 2020 at 17:59

Download – Flickering Lights Model and Script

How To – Make Flickering Lights in Roblox Studio

What’s up everyone, BuzzyBeth here – In this tutorial we’ll be learning how to make flickering lights at random intervals!

  • I created this very simple lamp post just composed of three different parts. It’s just two black parts and then the yellow part is going to be my light source.
  • Inside of that part i’m gonna go ahead and add a light source. You guys can use a point light, spotlight, or surface light either or is okay, but I want to use a spotlight to give that head-on effect with the light.
  • It’s not facing the right way so i’ll be changing that inside of the properties menu. Then change the brightness of it by using the slider.
  • Add a script inside of our part. We have a few variables, one which references our spot light and the second one is going to be just our part.
  • Now we’re going to create a while true do loop and the light is going to be disabled. We’re actually going to do math.random(0, 1) which means it can wait between 0 to 1 seconds. We’ll let them randomly choose how long it’s going to occur before light.enabled is equal to true.
  • Then we’re gonna do the same thing, we’re gonna do math.random for the wait time, but this time we’ll do zero to two seconds and then we’ll let the code choose the random time because we want this to be a random flicker!

Posted by8 years ago

Archived

How to make a flickering light in roblox

So I feel a little silly for asking, but how do I create a flickering light? More specifically how do I make it so that a brick changes in between two, three, or more point lights? Like if I wanted a flickering fire effect or some sort of crazy rave thing going on. I tried to reverse engineer free models that incorporated flickering point lights but I have yet to come to a conclusion. Some help would be mighty grateful.

Answered by

10 months ago

A Little code I whipped up. Might need further testing, but this code you can configure when it flashes and how long the intervals between the flashes. I've also added a PointLight You may need to change this depending on what light source you're using!.

Server Script!!: Heres the code!:

local Light = script.Parent -- Our Light
local PointLight = Light:FindFirstChild("PointLight",10) -- the PointLight Object, You may need to change this!

local FlickerInt = 3 -- seconds this light flickers  
local OffFlickerInt = 10 -- How much time to make this light not flicker in seconds!
local FlickerAtStart = true -- Do we flicker at the start of the game or not?

local FlickerRandomness = true -- is our flicker point random or not?
local MaxRandomTimeBetweenFlickers = 5
local MinRandomTimeBetweenFlickers = 1 

--// Below this line is internal variables these are set as this script is run!
--// ==========================================================================

local bisFlickering = false
local t = 0
local StartTime = tick()  -- Get the time this game started at in mili-secs
local LightMode = 1
local Saved = {
    PointLight = (function()
        if(PointLight ~= nil) then
            return {
                Enabled = PointLight.Enabled,
                Range = PointLight.Range,
                Color = PointLight.Color,
                Brightness = PointLight.Brightness
            }
        else
            return nil
        end
    end)(),
    FlickerInt = FlickerInt,
    OffFlickerInt = OffFlickerInt,
    FlickerAtStart = FlickerAtStart ,
    FlickerRandomness = FlickerRandomness,
    MaxRandomTimeBetweenFlickers = MaxRandomTimeBetweenFlickers,
    MinRandomTimeBetweenFlickers = MinRandomTimeBetweenFlickers
}
--// ==========================================================================
--// end of internal varibles


--// Main Loopy!
while true do
    t = tick() -- Grab Game Tick(frame) time!...
    local DT = t - StartTime -- Subtract the tick time from StartTime, this gives us the seconds since last update. Simular to workspace.DistributedGameTime but more accurate!
    if(FlickerAtStart == true) then -- do we flicker at start?

        if(DT <= FlickerInt) then -- Time is still under Flicker time!
            bisFlickering = true
        else -- Right we're Done flikering lets rest and reset the StartTime for next time!...
            StartTime = tick()
            bisFlickering = false
            FlickerAtStart = false
        end
    end
    if(bisFlickering == true) then-- Main Flicker if Statement, are we flickering?
        if(DT <= FlickerInt) then -- if DT is les then our Flicker time then randomise the LightIntensitiy via LightMode
            LightMode = math.random()
        else -- We're Not Flikering lets reset everything
            LightMode = 1
            bisFlickering = false
            if(FlickerRandomness == true) then
                OffFlickerInt = math.random(MinRandomTimeBetweenFlickers,MaxRandomTimeBetweenFlickers)
            else
                OffFlickerInt = Saved.OffFlickerInt
            end
        end
    else -- Nope Not Flikering Lets rest....
        LightMode = 1
        if(DT<= OffFlickerInt) then -- Snooore.......*PFFFT*..... Snoore.....
            bisFlickering = false
        else -- Wake up we're Flickering!....
            StartTime = tick()
            bisFlickering = true
        end
    end

--// Talk to our light Brick and if available our PointLight
    Light.Color = Color3.fromHSV(0, 0, LightMode)
    if(PointLight ~= nil) then
        PointLight.Range = (LightMode*100 / Saved.PointLight.Range) * 10
    end

    -- allways waiting.... No seriously, removing this will hang the game!
    wait()
end

Hopefully i've added some useful comments. If not, let me know. Oh! and simply put this script inside the light you want to flicker randomly. Also if you want it to talk to your Light Object just change line 2 to the name of your Light Object.

Hope this helps! :)