Having Roblox Detect Device Time

Hello.

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.

1 Like

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.

1 Like

Elaborate on ‘Spoof’? I’ll need a bit more information.

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.

1 Like

Okay, I just wanted an elaboration. Yeah I was completely aware of that and I am fine with it. I had to do that to get the badge in Pressure too.

1 Like

Cannot seem to get it to work.

I would like help on how to structure it correctly. This is what I have so far.
I’m very dumb at this :sob:

local dt = DateTime.now()

if dt:FormatLocalTime("H", "en-us") == 5 then
	print("test")
end

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.

1 Like

Actually Ignore this. Further LLM usage was able to solve it. Thanks.

(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

Hope this helps! :blush:

“LLM” and “AI” refer to the same thing in this context, though. I’m not really sure if…Saying “LLM” makes it sound any more professional.

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