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

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

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.

1 comment

0

you break out of the loop on line 23?

1 answer

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

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