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

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

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?

1 comment

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

1 answer

✓ Accepted answer

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 do statement, 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

1 comment

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.

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