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

Light on at certain times of day?

Asked by
Uroxus 350 Moderation Voter
9 years ago

How would you make a light turn on between lets say... 17:00:00 and 08:00:00 and for the time from 08:00:00 to 17:00:00 its off??

And how would you edit the script to make the light flash between the of 17:00:00 and 08:00:00? I've tried and dosent work, heres my script;

while true do
    if game.Lighting.TimeOfDay >= "17:00:00" then
        repeat
            game.Workspace.Light.PointLight.Enabled = true
            wait (2)
            game.Workspace.Light.PointLight.Enabled = false

        if game.Lighting.TimeOfDay >= "08:00:00" then
        game.Workspace.Light.PointLight.Enabled = false

Notes: The script is in a block, its a normal script, and im using 'PointLight' for the lighting.. Thanks =)

0
You did not add any kind of 'end' to end the blocks of code, that is the main problem in your script. TheeDeathCaster 2368 — 9y
0
I've added an 'end' to line 10, makes no difference, If I add one after line 6 It says "expected until(to close to repeat at line 3), got 'end' ??? Uroxus 350 — 9y
0
A 'repeat' loop requires an 'until == condition', not an 'end'. TheeDeathCaster 2368 — 9y
0
I've tried many variations of this script, still dosent work :l Uroxus 350 — 9y

1 answer

Log in to vote
1
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

What you're trying to do is compare a string with a numerical comparison. What you need to do is use game.Lighting:GetMinutesAfterMidnight() to calculate. Midnight is considered "00:00:00" in the time format.

"17:00:00" happens to be 1020 minutes after midnight, and "08:00:00" is 480 minutes after midnight.

Simple formula to get minutes after midnight, assuming "hh:mm:ss":

h * 60 + m + (s / 60) You will likely never need the s.

Also, change the code to do this:

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

    if minutes >= 1020 or minutes <= 480 then
        -- code if it's night time
    else
        -- code if it's day time
    end

    wait()
end
0
It works, Cheers man! =D Uroxus 350 — 9y
Ad

Answer this question