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

When Timer hits 0 it resets and stops working and ignores part of the script?

Asked by 6 years ago

Basically the Timer counts down from 10 minutes and then goes to night and vise versa. Yet once it hits 00:00 it goes to 10:00 as its supposed to but that's it. Does not change the lighting or anything and doesn't even continue to count down after it just stays there.

local lighting = game:GetService("Lighting")
local min = script.Minutes
local sec = script.Seconds
local night = script.Night

while true do
    wait(1)
    if sec.Value == 0 then
        if min.Value == 0 then
            if night == false then
                lighting.Brightness = 0
                lighting.OutdoorAmbient = Color3.fromRGB(93, 93, 93)
                lighting.TimeOfDay = "22:00:00"
                night = true
                min.Value = 10
            else
                lighting.Brightness = 1
                lighting.OutdoorAmbient = Color3.fromRGB(127, 127, 127)
                lighting.TimeOfDay = "14:00:00"
                night = false
                min.Value = 10
            end
        break
        else
            min.Value = min.Value - 1
        end
        sec.Value = 59
    else
        sec.Value = sec.Value - 1
    end
end

It's not a hard script I don't know why its not working any help is appreciated.

0
you break out of the loop on line 23? User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

This way is more efficient. Also, you probably need to put night.Value

local lighting = game:GetService("Lighting")
local min = script.Minutes
local sec = script.Seconds
local night = script.Night
local seconds = 600

while true do
    wait(1)
    seconds = seconds - 1
    sec.Value = seconds%60
    min.Value = math.floor(seconds/60)
    if seconds == 0 then
        lighting.Brightness = (night.Value and 1) or 0
        lighting.OutdoorAmbient = (night.Value and Color3.fromRGB(127, 127, 127))
            or Color3.fromRGB(93, 93, 93)
        lighting.TimeOfDay = (night.Value and "14:00:00") or "22:00:00"
        night.Value = not night.Value
        seconds = 600
    end
end

Ad

Answer this question