How to make a time range using :GetMinutesAfterMidnight()?

my objective is to make a time range that can work with :GetMinutesAfterMidnight(). here is what I have so far.

local dusk = {16, 18}
local night = {18, 6.2}

local timenow = game.Lighting:GetMinutesAfterMidnight() / 60
if timenow >= dusk[1] and timenow <= dusk[2] then
elseif timenow >= night[1] and timenow <= night[2] then


however any code put in these statements always goes to the else statement since both statements are not considered true. Is there any reliable way to make a time range with :GetMinutesAfterMidnight()?

Your if statement was a bit off. You can’t be greater than 18 and less than 6 at the same time. Instead it should look something like this:

local currentTime = game.Lighting:GetMinutesAfterMidnight() / 60

--if time is between 16:00 and 18:00 v	
if currentTime >= 16 and currentTime <= 18 then
--if time is between 18:01 and 6:20  v
elseif currentTime > 18 or (currentTime >= 0 and currentTime <= 6.2) then

full example you can paste into game:

1 Like