I've got a script that changes time, which works perfectly, and also a script which detects time of day, which works, but is inefficient.
lights = script.Parent:GetChildren()
game.Lighting.LightingChanged:connect(function()
local tam = game.Lighting:GetMinutesAfterMidnight()
if tam >= 390 and tam <= 1020 then
for i,v in pairs(lights) do
if v.Name == "Light" then
v.PointLight.Enabled = false
v.Material = Enum.Material.Plastic
end
end
else
for i,v in pairs(lights) do
if v.Name == "Light" then
v.PointLight.Enabled = true
v.Material = Enum.Material.Neon
end
end
end
end)
The reason for inefficiency is that it would enable the lights every time the time changes, which is obviously inefficient and laggy. But I don't know how to make it more efficient.
The time script is
local start, starthour = tick(), game.Lighting:GetMinutesAfterMidnight()
local speedModifier = 0.5
local gameTime = 0
lastTick = tick()
while true do
local delta = tick()-lastTick
gameTime = gameTime + delta * speedModifier
game.Lighting:SetMinutesAfterMidnight( gameTime + starthour)
lastTick = tick()
game:service('RunService').Stepped:wait()
end

1 comment
Have a boolean that you check/update to tell if you've already turned the lights on/off.