How do I check if it’s a specific time, like if it’s 6:00 PM, because I want to write a code where if a certain date/ time reached then trigger something, e.g. if it’s 14th July 2022 6:00PM then print (“It’s 6pm”)
And another question, is the time global meaning it will activate regardless of people’s timezone?
If you’re on about the time of day in a server then you can get it using Lighting:GetMinutesAfterMidnight()
Here is an example:
local Lighting = game:GetService("Lighting")
function CheckTime()
if Lighting:GetMinutesAfterMidnight == 1080 then
print("It's 6 PM")
end
end
Lighting.Changed:Connect(CheckTime)
Oh ok, so if a USA player joins a server and a EU player joins a different server, the os.time would be the same for both of the servers? or how does it work for the UTC to be maintained
Reason why i’m asking is because, i want to trigger something when a certain time is reached, at the same time on all servers that have the script. So if the next hour clock occurs let’s say it prints something.
So if it’s 5:43 PM, but then next hour clock, i.e 6:00PM occurs, then it prints something, please can you show me how i can do this?
UTC (Universal Coordinated Time) is always the same, no matter what.
You can try this for a triggered event:
local plrtime = tonumber(os.date("%H", os.time()))
local seconds = tonumber(os.date("%S", os.time()))
local ampm = os.date("%p", os.time())
local debounce = false
while wait() do
plrtime = tonumber(os.date("%H", os.time()))
seconds = tonumber(os.date("%S", os.time()))
ampm = os.date("%p", os.time())
if plrtime == 6 and ampm == "PM" and seconds == 0 and debounce == false then
print("It's 6:00!")
debounce = true
--do other code, if necessary
else
debounce = false
end
end
Thank you very much, i really do appreciate your help, I humbly ask, if you do not mind please can you show me how I can also get the day and month and year? I would like to also apply those in the checks i.e. if day == “12th” and month == “July” or 06, etc
Simple, just add extra checks to the if statement:
local plrtime = tonumber(os.date("%H", os.time()))
local seconds = tonumber(os.date("%S", os.time()))
local extratime = os.date("%B %d", os.time())
local ampm = os.date("%p", os.time())
local debounce = false
while wait() do
plrtime = tonumber(os.date("%H", os.time()))
seconds = tonumber(os.date("%S", os.time()))
ampm = os.date("%p", os.time())
if plrtime == 6 and ampm == "PM" and seconds == 0 and debounce == false and extratime == "July 12" then
print("It's 6:00!")
debounce = true
--do other code, if necessary
else
debounce = false
end
end
Yes, I’ll quote to Roblox’s documentation:
“This library currently serves the purpose of providing information about the system time under the UTC format.”
Thank you, so if a USA player joins a server and a EU player joins a server, since the while checker is using UTC, it will both trigger at same times regardless of their differing (EU/USA) timezones?
In army time, 00:20 equals 12:20, so you might need to add adjustments.
I just went off of the documentation.
Either the documentation has false information, or there’s something I didn’t get.