# Is there a way to detect each time a minute has past live?

Hi, I was wondering if there is a way to detect each time a minute has passed live?

1 Like

You mean the global time? You would use `os` library, and maybe `time` or `date`. Iâ€™m not accurate on it.

1 Like

I believe you can use os.date and get the Minute from it?

No, I want to run a code whenever a minute has been passed live.

There is no event when a minute has passed in real time. You would need to use os.time() which gets the time since unix epoch(January 1, 1970, midnight) in seconds. You would then need to do math to determine how long it is until a minute passes, which then you can run your event.

I actually do have a script, but itâ€™s not live, hereâ€™s the code of it:

``````local re = tick()

while wait(1) do
if math.floor(tick() - re) >= 60 then
print("1 minute passed!")
re = tick()
else
print(math.floor(tick() - re))
end
end
``````

You want it on the minute at the dot, and not just after a minute if im understanding this correctly?

Just for preventing issues, I just `>=`.

Are you trying to get the event to fire when the minute in real time changes, or just after a minute passes in the server time which isnt lined up with exact time? It should work if your just trying to get it to run every minute not lined up with real time.

I want to fire an event when a minute has been passed in real time.

Thinking about this, I think the best way to determine if a minute would be to divide seconds since epoch by 60, and check if its a whole number. If it is a whole number, that would mean its divisible by 60 and a minute has changed. Im not sure the best way to determine if its a whole number, maybe check to see if theres a â€ś.â€ť in the text? Not sure.

Oh, so you mean `os.time() or tick() / 60` .

os.time() returns in UTC, when tick() returns local time. I think you should use os.time() because im guessing this is server sided(?). Dividing it by 60 then checking if its a whole number which checks if a minute has passed in real time.

I think I guessed something, here it is:

``````while wait(1) do
local minutesSinceEpoch = os.time() / 60 -- This will return minutes since the Epoch
-- I don't know how to check if a number is a whole number. I suck at maths
end``````

You can just use `wait(60)`? A minute in game is still a minute in real life.

``````while true do
print"a minute has passed since runtime"
wait(60)
end
``````

There of course will be a maximum of a 59 second delay because this is relative to runtime not relative to time since epoch, but it is fine probably for whatever youâ€™re doing.

Itâ€™s not real. loops arent real time

what I want is real-time, and loops arenâ€™t relative to the time since epoch

Okay, I guess you can just do something like this.

``````while true do
local Seconds = os.time()

if (Seconds % 60 == 0) then --// Is the remainder division of Seconds and 60 equal to 0? if so its been one minute.
local Minutes = Seconds / 60 --// Minutes passed

print("Minutes relative to EPOCH: ", Minutes)
wait(1) --// Wait because it is still a given minute for an entire second
end

wait() --// ~0.03 delay to prevent the main lua thread from hanging.
end
``````

2 Likes

Thanks, it worked! I still donâ€™t understand the `%` sign. Can you give an example?

It calculates the remainder