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

How do you make a light that flicker when it is evening/18:00:00?

Asked by 4 years ago
Edited 4 years ago

Hello,

I have a little problem and is easy to be fixed I guess but I don't know how.

I have streetlights in my game and they must pretend to be broken.

My intention was that they will start flickering at 6PM (18:00:00) till 6AM (06:00:00).

The problem is they stop flickering when it is midnight/00:00:00.

Line 25 to 29 is the flickering part.

Here the script.

local Lights = workspace:WaitForChild('Lights')
local BrokenStreetLights = Lights:WaitForChild('BrokenStreetLights')
local Lighting = game:GetService('Lighting')

function SetLights(bool)
    if bool == "on" then
        for i,v in pairs(BrokenStreetLights:GetDescendants()) do
            if v:IsA('SpotLight') and v.Parent:IsA('BasePart') then
                v.Enabled = true
                v.Parent.Material = Enum.Material.Neon
                v.Parent.Transparency = 0
            end
        end
    elseif bool == "off" then
        for i,v in pairs(BrokenStreetLights:GetDescendants()) do
            if v:IsA('SpotLight') and v.Parent:IsA('BasePart') then
                v.Enabled = false
                v.Parent.Material = Enum.Material.Glass
                v.Parent.Transparency = .25
            end
        end
    end
end

while wait() do
    if Lighting.TimeOfDay >= "18:00:00" then
        SetLights("off")
        wait(0.05)
        SetLights("on")
    elseif Lighting.TimeOfDay >= "06:00:00" then        
        SetLights("off")
    end
end

I hope someone can help me. Keep in mind im a beginning scripter.

1 answer

Log in to vote
1
Answered by
AspectW 431 Moderation Voter
4 years ago

Hey, to solve your problem you should use GetPropertyChangedSignal. Here's an example on how you'd use it in your case.

local Lighting = game:GetService("Lighting")

Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
    if Lighting.TimeOfDay == "18:00:00" then
        SetLights("off")
        wait(0.05)
        SetLights("on")
    elseif Lighting.TimeOfDay == "06:00:00" then
        SetLights("off")
    end
end)
0
I tried the code and it doesn't work or I'm doing something wrong. I tried inserting the code at line 25 and 26 so I did it with and without the while loop. rotaapjes 22 — 4y
0
Replace line 25 in your script with line 3 in this script, and add a closing paranthesis at line 33 in your script. AspectW 431 — 4y
0
I did what you said and now I have the same result as before the light is flickering.. BUT it stops when midnight/00:00:00 hits in roblox. rotaapjes 22 — 4y
0
You obviously need to remove the >= in line 26 and 30, make them both == AspectW 431 — 4y
View all comments (2 more)
0
It doesn't work, its not flickering anymore. rotaapjes 22 — 4y
0
I assume you have a "Day/Night" cycle then, causing the TimeOfDay to not reach exactly 18:00:00/06:00:00 AspectW 431 — 4y
Ad

Answer this question