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 comment
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?