I have plans to make an easter egg for one of my games in which only occurs at a specific time. The experience Pressure did a similar mechanic, where a certain monster spawns at 3 AM on the device’s time.
Something similar appears in the game “Undertale” with a secret boss spawning at a specific date and time.
I would like to know how to achieve something like this, where when a certain time is reached (4:00 P.M, 10:00 A.M, etc.) I can have that be detected by a script, and from there, it can fire an event.
I would also like to know if it can account for specific dates in the year as well.
DateTime.now will give you the current time from the players device or their local time when ran in a LocalScript. However, please keep in mind it’s possible to spoof your local time via device settings.
In this context, a player can go into their device settings and change their local time to 3 AM even when it is not actually 3 AM therefore tricking your program. Multiple insanely niche resources have more info about how it can be used to bypass waiting periods, or other use cases.
FormatLocalTime returns a string value rather than a integer. You’d have to first convert it into a number using tonumber. Just as a note, for quicker responses it might be worth referencing the Roblox Docs, an LLM (for smaller cases like this, and if you have no ethical objections), or outputting the value of dt:FormatLocalTime to see what you are actually comparing.
I tried putting some input into the LLM and I got this code:
-- // CONFIGURATION
local targetMonth = 11
local targetDay = 9
local targetHour = 17 -- 5 PM
local targetMinute = 10
-- // The event in ReplicatedStorage you want to fire
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- // Internal flag to avoid firing repeatedly during the same minute
local fired = false
while true do
task.wait(1)
local dt = DateTime.now():ToLocalTime()
-- Extract components safely as numbers
local month = tonumber(dt:FormatLocalTime("MM", "en-us"))
local day = tonumber(dt:FormatLocalTime("dd", "en-us"))
local hour = tonumber(dt:FormatLocalTime("HH", "en-us"))
local minute = tonumber(dt:FormatLocalTime("mm", "en-us"))
if month and day and hour and minute then
print(string.format("Current time: %02d/%02d %02d:%02d", month, day, hour, minute))
end
-- Check if current time matches target
if month == targetMonth
and day == targetDay
and hour == targetHour
and minute == targetMinute
and not fired then
fired = true
ReplicatedStorage.CATACLYSM:FireServer() --Problematic <<
print("🎉 Target time reached! Event fired.")
elseif minute ~= targetMinute then
-- Reset once the minute passes
fired = false
end
end
My problem now is that I want my event to only be visible only for the person at that specific time, but it is forcing me to use “FireServer()” instead.
(I’ve a feeling you’re trying to say you’re using an AI to help you with the code by using a euphemism for it to throw people off, so you avoid being criticized for it.)
I don’t use, nor support AI for coding. This was my first ever time doing such a thing since this was such a complicated subject. It did help, thanks to anythingoliver’s advice.
It also sounds more professional and more neutral than using the word “AI”.
To help others who are trying to solve a similar problem, this is what I got.
This works only for the client, and the client only. Unless you use events.
local ts = game:GetService("TweenService")
--Use what time you need
local targetMonth = 11
local targetDay = 9
local targetHour = 19
local targetMinute = 37
local fired = false
while true do
task.wait(1)
local now = DateTime.now():ToLocalTime()
local year = now.Year
local month = now.Month
local day = now.Day
local hour = now.Hour
local minute = now.Minute
if month == targetMonth and day == targetDay and hour == targetHour and minute == targetMinute and not fired then
fired = true
--insert your code here
elseif minute ~= targetMinute then
fired = false
end
end