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

How do you script a light that turns on a curtain time?

I need help on making a new game, it's a city and the street lights and windows lights need to turn on without me doing it everyday on the server, sorta like of GTA where they turn on at night and not in day, it has been bugging me for A LONG TIME, the is no script but if someone can write it in the comment section that would be amazing thank's!

1 answer

This question has been asked atleast 3 times before, But I shall answer it again.

Midnight is considered to be 00:00:00

Say I want the lights to turn on at 17:00:00 then I'd need to put 1020 (As 17:00:00 is 1020 minutes after midnight) and I want them to turn off at 08:00:00.... I'd put 480 (As 08:00:00 is 480 minutes after midnight)

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

    if minutes >= 1020 or minutes <= 480 then -- Between 17:00:00 and 08:00:00 I want the lights to be on
        script.Parent.SpotLight.Enabled = true 
		
    else
       	script.Parent.SpotLight.Enabled = false -- Any other time I want the light to be off. 
    end

    wait()
end

This must be inside of a normal script, inside the block that has the light object inside of it. You could also change the path that links to the light object if you wish.

If my answer helped you, please click accept answer to the right of this. If not, please do question me :)

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