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

Turn PointLight Off During Day?

Asked by 7 years ago

I have a changing point light on a monument, and I want it to only come on at night but I can not seem to get it to turn off during the day. Any help? Thanks in advance!

while true do
wait(2)
script.Parent.PointLight.Color=Color3.new(math.random(0,255)/255,1,math.random(0,255)/255)
wait(2)
script.Parent.PointLight.Color=Color3.new(math.random(0,255)/255,1,math.random(0,255)/255)
end

L = game:GetService("Lighting") 
local light = script.Parent.PointLight

while true do 
    wait(1)
    T = L:GetMinutesAfterMidnight()
    L:SetMinutesAfterMidnight(T + 1)
    if T < 300 then --Night time, after midnight.
        game.Lighting.OutdoorAmbient = Color3.new(30/255,30/255,30/255)
    elseif T > 300 and T < 390 then --Dawn, sun rise.
        game.Lighting.OutdoorAmbient = Color3.new((30+(T-300)/1.5)/255,(30+(T-300)/1.5)/255,(30+(T-300)/1.5)/255)
    elseif T > 390 and T < 600 then --Morning.
        game.Lighting.OutdoorAmbient = Color3.new((90+(T-390)/7)/255,(90+(T-390)/7)/255,(90+(T-390)/7)/255)
        light.Enabled = false
    elseif T > 600 and T < 840 then --Day time.
        game.Lighting.OutdoorAmbient = Color3.new(120/255,120/255,120/255)
    elseif T > 840 and T < 1050 then --Afternoon.
        game.Lighting.OutdoorAmbient = Color3.new((120-(T-840)/7)/255,(120-(T-840)/7)/255,(120-(T-840)/7)/255)
    elseif T > 1050 and T < 1140 then --Evening, sun set.
        game.Lighting.OutdoorAmbient = Color3.new((90-(T-1050)/1.5)/255,(90-(T-1050)/1.5)/255,(90-(T-1050)/1.5)/255)
        light.Enabled = true
    elseif T > 1140 then --Night time, before midnight.
        game.Lighting.OutdoorAmbient = Color3.new(30/255,30/255,30/255)
    end     
end

1 answer

Log in to vote
0
Answered by 7 years ago

Here. ClockTime is 0-24, 12 is noon where 24 is midnight.

while wait() do
    if game.Lighting.ClockTime > 7 and game.Lighting.ClockTime < 8 then
        --Do Stuff
    elseif game.Lighting.Clocktime > 8 and game.Lighting.ClockTime < 9 then
        --Do Stuff
    end -- Repeat the elseif statements if you need more.
end
0
Thank you for responding. I tried this script and it's not working for me. I have no idea what I'm doing wrong. Is there another way to automate the light? arkenzii 6 — 7y
Ad

Answer this question