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

How to Print something with TimeOfDay?

Asked by
Vezious 310 Moderation Voter
9 years ago
game.Lighting.TimeOfDay.Changed:connect(function()
local Time = game.Lighting.TimeOfDay
if Time == "18:00:00" then 
print("ITS 18!")
elseif Time == "6:00:00" then
print("ITS 6")
end
end)

What's Wrong with this script?

0
Your problem is lines 3 and 5 of the code; The 'if' statement is only checking if Variable 'Time' is exactly equal to '1080' or '6:00:00'; 'TimeOfDay' runs by a 24 clock, but, the issue is that your comparing the 'TimeOfDay' to a specific time. :P TheeDeathCaster 2368 — 9y

2 answers

Log in to vote
-1
Answered by
hudzell 238 Moderation Voter
9 years ago
game.Lighting.Changed:connect(function()
    local time = game.Lighting:GetMinutesAfterMidnight()
    if time == 1080 then
        print"It's 6 pm!"
    elseif time == 360 then
        print"It's 6 am!"
    end
end)
0
Explain what you did. HungryJaffer 1246 — 9y
0
Well, :GetMinutesAfterMidnight() will do just that, get how many minutes the current time is after midnight. So 6 AM would be 360 minutes after midnight, and 6 PM is 1080 after midnight. To get the minutes after midnight, calculate what the hour is times 60 hudzell 238 — 9y
1
This Worked! Thanks! Vezious 310 — 9y
Ad
Log in to vote
-2
Answered by 9 years ago
game.Lighting.Changed:connect(function(property)
    if property == game.Lighting.TimeOfDay then
        if game.Lighting.TimeOfDay == "18:00:00" then 
            print("ITS 18!")
            elseif game.Lighting.TimeOfDay == "6:00:00" then
            print("ITS 6")
        end
    end
end)

You dingus! you can't used the changed event on a specific property, it's meant for instances. Although it returns the property of the instance that was changed. so if we check if the property was TimeOfDay that changed, then we could successfully do the print.

0
no offense, dingus. HungryJaffer 1246 — 9y
0
Nope, Does not work. Vezious 310 — 9y
0
i'd just use a while loop HungryJaffer 1246 — 9y
0
The problem with your code jaffer is you had the script looking for the property, not the name. If you were to do it your way, you'd change "if property == game.Lighting.TimeOfDay then" to "if tostring(property) == "TimeOfDay" then" hudzell 238 — 9y
View all comments (2 more)
0
tostring(property) will return "6:00:00" HungryJaffer 1246 — 9y
0
No, it will not actually. To find the value of the property, you would have to find it again in the script by using game.Lighting.TimeOfDay. hudzell 238 — 9y

Answer this question