Making an event happen at a certain time each day

So I am trying to make an event that happens at 6 AM/PM EST every day, I looked on the dev forum and found some stuff but never got it to work, can you guys help? :heart:

Use os.time to get the time. Figure it out from there :tongue:

I am actually getting somewhere, I found out that using os.date("!*t") gives you a table of time, but I don’t understand the timezone.

What are you getting when using it?

So here is the basic part,

You are trying to have a event happen at exact 6:00 in the morning and the after noon, under Eastern Standard Time, The UTC (Coordinated Universal Time) time for EST is UTC-5, which means that Eastern Standard Time is exactly 5 hours behind UTC Time, However you also have to Account for Daylight Savings Time during Spring and Summer where the Hour is ahead by 1, in the case, its called (EDT) instead of (EST), which this time is exactly 4 hours behind UTC time instead of 5.

os.date() could probably help you here, the format *t is your Local time, while format !*t is your UTC time, which if you are living in an Area where EST or EDT is used, it will be ahead by either 4 or 5 hours, UTC time can be trusted, and all you need to do is subtract the Hour by 5, then check if the resultant is equal to 6 (12 hour clock or 24 hour clock (6 in the morning or afternoon)) or 18 (24 hour clock (6 in the afternoon)).

1 Like

This helped a ton, is UTC time a 24 hour clock?

UTC is a time-zone, not a clock.
This needs to be decided properly, if you want to have an event every day at certain time your time-zone, you have to calculate it from UTC, but remember, that players from the other part of world will have the event in different time.
There are lot of utilities on Google, which will help you calculate the time from your time-zone to UTC.
Then take that time, convert it into timestamp for today and when that timestamp is achieved, run the event.
DateTime.fromUniversalTime(2023, 5, 31, 6, 0, 0).UnixTimestamp should get you timestamp for 6th hour in UTC time-zone.

Also DateTime.new():ToLocalTime() will give the local timezone if run on client. But is obviously less secure if you need it for anything important.

Thank all of you guys so much! I used UTC time and converted it to EST to make it easier, and used if statements to check if it was in a time period!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.