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

Issues with making a time of day script?

So, I'm making a script that gradually increases the time of day until the time hits 10:00:00. Here's the script:

local ToD = game.Lighting.TimeOfDay
repeat
wait(0.1)
	ToD:SetMinutesAfterMidnight(ToD:GetMinutesAfterMidnight() + 1)
until ToD == "10:00:00"

The problem is that the output says GetMinutesAfterMidnight() is a nil value and the script breaks.

Output: 14:38:18.338 - Workspace.darkness:4: attempt to call method 'GetMinutesAfterMidnight' (a nil value)

I have no idea what's wrong with this script, but I bet some of you guys can help me with this.

2 comments

1

You are attempting to call 'GetMinutesAfterMidnight' on 'TimeOfDay', not 'Lighting', consider changing to [game.Lighting:GetMinutesAfterMidnight] 'same with [SetMinutesAfterMidnight'.

0

Oh, ok. I'll try it out.

1 answer

GetMinutesAfterMidnight and SetMinutesAfterMidnight are both methods of Lighting, not TimeOfDay. It is also generally a bad idea to set a variable to a property, because the variable becomes what the property equals and is in no way connected to the property.

repeat
	wait(0.1)
	game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight() + 1)
until game.Lighting.TimeOfDay == "10:00:00"

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