Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I check what time of the day it is in a script?

Asked by 10 years ago

I've got a function in my script so that when (below) is true, it will trigger the loop.

1while game.Lighting.TimeOfDay > 070000 and game.Lighting.TimeOfDay < 210000 do

The only problem is that my example doesn't work. The Output is telling me "attempt to compare number with string" So how am I supposed to check the TimeOfDay value within a script?

0
Your script doesn't work because the TimeOfDay property holds a string value; http://wiki.roblox.com/index.php?title=API:Class/Lighting/TimeOfDay Redbullusa 1580 — 10y

1 answer

Log in to vote
2
Answered by
Uroxus 350 Moderation Voter
10 years ago

Midnight is considered "00:00:00" In roblox's time format. So 07:00:00 will be 420 and 21:00:00 is considered to be 1260. And as this is within a while true dostatement, It will run for as long as the script exists, All you have to do is code what you want to happen between these times

01while true do
02    local minutes = game.Lighting:GetMinutesAfterMidnight()
03 
04    if minutes >= 420 or minutes <= 1260 then
05        --Do stuff here
06    else
07       --Do something else here.
08    end
09 
10    wait()
11end
0
Thank you! It works, I tried, but it just doesn't work with the script I'm trying to get it to work in. Hmm, maybe it's just me. I'll have to try and look for a fix. Thanks anyway. Nickyninja07 35 — 10y
Ad

Answer this question