I'm following the simple day/night script from the ROBLOX Wiki (http://wiki.roblox.com/index.php?title=Making_a_Day/Night_Cycle). I thought, as a challenge, was to have two parts in a lamp that gave off a light and a single script would handle how the lights behaved in both of the parts.
local minutesAfterMidnight = 0
local lightParts = game.Workspace.Lamp.Light:GetChildren() -- this would get the parts containing Point Lights
for i, v in ipairs(lightParts) do -- looping through each part
lights = {} -- table to contain ACTUAL point lights
table.insert(lights, v:GetChildren()) -- insert the two Point lights into the the 'lights list'
for j, k in ipairs(lights) do -- loop through lights
if game.Lighting.TimeOfDay == "06:00:00" then -- check if it is 6:00AM
k.Parent.Material = Enum.Material.Plastic
k.PointLight.Enabled = false -- turn off lights
end
end
end
while true do
minutesAfterMidnight = minutesAfterMidnight + 1
game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
wait(.1)
end
The logic doesn't seem to be adding up and the lights won't turn off when it's 6:00AM. I tried putting in a print statement to print the values of the 'lights' list but it was empty! Even though I inserted the lights there right?

1 comment
That is because your script never checks for the TimeOfDay again after it has run once. Tranform the for loops into a function, and call it every time the while loop runs.