Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making something print at a specified time?

I'm trying to make a sound play when a raid starts which begins at a specific time, (irl time) but when I tried to print something it didn't work.

local hour = os.date("!*t") ["hour"]
local minute = os.date("!*t") ["min"]

if hour == 7 and minute == 5 then
	print("Hmm")
end

(I used print just to test it)

[EDIT]

local hour = os.date("!*t") ["hour"]
local minute = os.date("!*t") ["min"]

while true do
	wait() --i added this so my game doesnt break
if hour == 2 and minute == 55 then
	print("Hmm")
end
end

9 comments

0

its important to know os.date uses UTC so maybe it didnt pass that

0

converts your hour to UTC hour

0

That code will only check once as soon as the game runs, so if it's not the correct time as soon as you hit the start button it wont work. You could put it in a loop instead to repeatedly check.

0

@prolua I know it goes to UTC I just changed it

0

@mattscy I added a loop but it still didn't print

0

while true do

0

What other loop would I use??

0

It works fine for me. Show us the updated version with your while loop.

0

@Cousin_Potato added it

1 answer

You need to also update the time variables inside the loop, otherwise they will be set only once at the beginning of the script and never again even as the clock increments.

while true do
	local hour = os.date("!*t") ["hour"]
	local minute = os.date("!*t") ["min"]

	if hour == 14 and minute == 17 then
	    print("Hmm")
	end	
	wait()
end

This discussion is preserved as it was. New answers, comments, and votes are closed.