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

How to Print something with TimeOfDay?

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?

1 comment

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

2 answers

✓ Accepted answer
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)

3 comments

0

Explain what you did.

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

1

This Worked! Thanks!

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.

6 comments

0

no offense, dingus.

0

Nope, Does not work.

0

i'd just use a while loop

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"

0

tostring(property) will return "6:00:00"

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.

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