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

Why do my lights turn off, but not back on?

Pretty self explanatory... They'll turn off at 06:00:00, but when it comes to 18:00:00, they don't turn on.. :/

Update (Added prints)

minutesAfterMidnight = 0

function checkDecendants(parent, enabled)
	print(enabled)
    for i, v in pairs(parent:GetChildren()) do
        if #v:GetChildren() > 0 then
            checkDecendants(v)
        end

		if v.Name == "SpotLight" then
			v.Enabled = enabled
			if enabled then
				v.Parent.Material = Enum.Material.Neon
			else
				v.Parent.Material = Enum.Material.SmoothPlastic
			end
		end
    end
end


while true do
	minutesAfterMidnight = minutesAfterMidnight + 2
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(0.1)
	
	print(game.Lighting:GetMinutesAfterMidnight(), minutesAfterMidnight)
 
	if game.Lighting:GetMinutesAfterMidnight() == 360 then		-- checks for 6AM
		print("Off")
		checkDecendants(game.Workspace, false)
	elseif game.Lighting:GetMinutesAfterMidnight() == 1080 then		-- checks for 6PM
		print("On")
		checkDecendants(game.Workspace, true)
	end
end

output:

4 4  -358 358
360 360
Off
false
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
362 362
364 364 - 1078 1078
1080 1080
On
true
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
1082 1082
1084 1084

2 comments

0

why not just if minutesAfterMidnight instead of the whole thing from lighting

0

Because minutesAfterMidnight doesn't reset to 0.

1 answer

Fix.. I realized that calling checkDecendents(v) didnt take the enabled parameter, so it passed nil as the argument.

minutesAfterMidnight = 0

function checkDecendants(parent, enabled)
    for i, v in pairs(parent:GetChildren()) do
        if #v:GetChildren() > 0 then
            checkDecendants(v, enabled)
        end

		if v.Name == "SpotLight" then
			v.Enabled = enabled
			if enabled then
				v.Parent.Material = Enum.Material.Neon
			else
				v.Parent.Material = Enum.Material.SmoothPlastic
			end
		end
    end
end


while true do
	minutesAfterMidnight = minutesAfterMidnight + 2
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(0.1)
	
	print(game.Lighting:GetMinutesAfterMidnight(), minutesAfterMidnight)
 
	if game.Lighting:GetMinutesAfterMidnight() == 360 then		-- checks for 6AM
		checkDecendants(game.Workspace, false)
	elseif game.Lighting:GetMinutesAfterMidnight() == 1080 then		-- checks for 6PM
		checkDecendants(game.Workspace, true)
	end
end

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