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

{SOLVED} Lights only on at night?

Asked by 9 years ago

I have this so far, I know I'm missing the checking part but I don't know how to do it, I'm new to scripting.

function timeFix()
    if game.Lighting.TimeOfDay >= "00:00:00" and game.Lighting.TimeOfDay <= "06:00:00"
    or game.Lighting.TimeOfDay  >= "18:00:00"
    then script.Parent.Enabled = true
    else
    script.Parent.Enabled = false
    end
end

The parent is a spotlight, the rest is pretty self explanatory.

1 answer

Log in to vote
4
Answered by
2eggnog 981 Moderation Voter
9 years ago

You're attempting to compare two strings as if they were numbers. Rather than using TimeOfDay, use the GetMinutesAfterMidnight() method instead.

function timeFix()
    minutes = game.Lighting:GetMinutesAfterMidnight()
    if minutes >= 0 and minutes <= 360 or minutes >= 1080 then
    script.Parent.Enabled = true
    else
    script.Parent.Enabled = false
    end
end

while wait(1) do timeFix() end --This will cause the timeFix() function to run once every second.
0
Silly mistake. I forgot a space. Edited. 2eggnog 981 — 9y
0
How can I get it to automatically update itself? At the moment it doesn't turn off automatically when it becomes dark. DEVEL0PMENT 35 — 9y
0
Added it to my answer. 2eggnog 981 — 9y
0
You're the best. Thanks. DEVEL0PMENT 35 — 9y
Ad

Answer this question