Hello. Can you make a better optimization for my day/night script. So less ping or lag.
Script:
local lighting = game:GetService("Lighting")
local minutes = 840
while true do
wait(0.25)
lighting:SetMinutesAfterMidnight(minutes)
minutes = minutes + 0.1
end
@SnarlyZoo Is correct that your script will not cause lag. However, it can be improved in other ways.
wait(0.25) will not always wait exactly 1/4 of a second. wait is an unstable function and doesn’t always do what you want.
You don’t need to update lighting every fourth of a second anyways
Combining these two pieces of advice:
local lighting = game:GetService("Lighting")
local minutes = 840
local GAME_MIN_PER_REAL_MIN = 10 -- game time runs 10 times faster than real time
local DO_UPDATE_EVERY = 5 -- update lighting every 5 seconds (independent of above setting)
while true do
lighting:SetMinutesAfterMidnight(minutes)
local secondsActuallyWaited = wait(DO_UPDATE_EVERY)
minutes += GAME_MIN_PER_REAL_MIN * secondsActuallyWaited / 60
end