So what this code does is change the lighting depending on the time. The sunset/sunrise is kind of a transition.
The first time I wrote this, I didn’t have the timeCheck() function that’s currently in the code now.
It’s more readable and looks a helluva lot better than using the if-statement itself to check the time, but I’m wondering if it’s going to perform any different than before (it runs every 0.5 seconds in a Heartbeat timer). If doing this is more efficient and a scripting improvement in general, should I do this more often to simplify if-statements in the future?
The code:
--timeCheck() checks if game.Lighting.ClockTime is within the range of numbers specified
local sunsetCheck = timeCheck(6,7) or timeCheck(16.5,17.5)
if sunsetCheck and not sunset then
print("sunset / sunrise")
--this function creates a tween and plays it
tweenCreate_Play(game.Lighting, sunsetTween, {OutdoorAmbient = conditionTables.lightingValues.sunSetRise})
sunset = true
elseif not sunsetCheck and sunset then
print("day / night")
local dayNightCheck = timeCheck(7,16.5)
local tweenGoal
if dayNightCheck then
tweenGoal = conditionTables.lightingValues.afternoon
else
tweenGoal = conditionTables.lightingValues.evening
end
tweenCreate_Play(game.Lighting, sunsetTween, {OutdoorAmbient = tweenGoal})
sunset = false
end
Also, any additional advice would help. I’m not exactly the greatest scripter haha, thanks!