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 9 years ago

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

while 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 — 9y

1 answer

Log in to vote
2
Answered by
Uroxus 350 Moderation Voter
9 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

while true do
    local minutes = game.Lighting:GetMinutesAfterMidnight()

    if minutes >= 420 or minutes <= 1260 then
        --Do stuff here
    else
       --Do something else here. 
    end

    wait()
end
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 — 9y
Ad

Answer this question