Divde the Number by 60
or Check if the Number is equal to a Certain Value, For Example: 5 AM According to you Script will be Exactly 300
Seconds, with 6 AM Being 360 Seconds, you can check if the Number is within a Specific Time, like so:
if x>= 300 and x < 360 then -- if the Number
-- code
end
Or you can check if the Number is number a Specific Time by dividing the Number by 60, if you have 300 divided by 60, it will be 5, but if you have a Number in Between, it will be slighly bigger, so you can round the number down using math.floor
, like so:
if math.floor(x/60) == 5 then
-- if we have 300, 300 will fit into 60, 5 times
-- 60, 120, 180, 240, 300 (5 times)
-- If the Number is over 300, but not yet 360, it will be a Decimal when divide by 60
-- which will be in between 300 (5 AM) and 360 (6 AM)
-- math.floor is so we can round down, and check the approximate time
-- code
end
However to Run the time, I recommend using RunService.Heartbeat
to have the Code run within the exact time, you can have a Variable Reset when a Game Starts, and Have it run when the Game is playing.
local timePassed = 0
-- timePassed is to keep track of the time that passed during the game
-- I will refer to this as 'x'
local nightTime = 6*60
RunService.Heartbeat:Connect(function(Delta) -- Delta is important
x = math.min(nightTime, x + Delta)
-- x is out example Variable to keep track of the time
-- math.min is used to the time doesnt go over the expected time
-- Delta (or just DeltaTime) just means the Difference between Time, which in this case, the Frames
-- Added up, It should be added as if It were a timer of sorts.
end)