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

Day Night Lights not working?

Asked by 1 year ago

So im trying to make a script in where the lights (surfacelights) turn off during the day and turn on at night. I don't really have much experience with scripting and I'm using a script that works similarly that my friend made. I edited it but it doesnt work. Its giving me no errors in the console so I don't know what the issue is. Here is the script.

while true do wait(0.1) if math.floor(game.Lighting:GetMinutesAfterMidnight()/60) >= 18 or math.floor(game.Lighting:GetMinutesAfterMidnight()/60) < 6 then for i, v in pairs(script.Parent.Lights.Light.SurfaceLight:GetChildren()) do v.Brightness = 0 end else for i, v in pairs(script.Parent.Lights.Light.SurfaceLight:GetChildren()) do
v.Brightness = 0.5 end end end

1 answer

Log in to vote
0
Answered by 1 year ago

This script works. You should put it in the same part where the surfacelights are and make sure that it isn't a children of any object that wont make it show the surfacelight. These object could be like decals or gui. Btw this also makes the time start at midnight.

minutesAfterMidnight = 0
while true do
    wait()
    minutesAfterMidnight = minutesAfterMidnight + 1

    local minutesNormalised = minutesAfterMidnight % (60 * 24)
    local hours = minutesNormalised / 60

    game.Lighting.ClockTime = hours

    if game.Lighting.TimeOfDay >= "06:00:00" and game.Lighting.TimeOfDay < "19:00:00" then 

        script.Parent.SurfaceLight.Enabled = false

    else

        script.Parent.SurfaceLight.Enabled = true

    end
end
Ad

Answer this question