So I have this script that is supposed to turn on all the streetlights in my game. All the streetlights are a put in a folder called "StreetLights" and have a part named "Light" with a spotlight in it.
My script attempts to cycle through the streetlights folder and turn them all on or off depending on the time, however it fails to do so.
minutesAfterMidnight = 7 * 60
while wait(0.1) do
minutesAfterMidnight = minutesAfterMidnight + 10
game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
end
function streetLights()
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then
local streetlights = game.Workspace.Map.StreetLights:GetChildren()
for i = 1, #streetlights do
if streetlights[i]:FindFirstChild("Light") ~= nil then
streetlights[i].Light.Material = "SmoothPlastic"
streetlights[i].Light.SpotLight.Enabled = false
end
end
end
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then
local streetlights = game.Workspace.Map.StreetLights:GetChildren()
for i = 1, #streetlights do
if streetlights[i]:FindFirstChild("Light") ~= nil then
streetlights[i].Light.Material = "Neon"
streetlights[i].Light.SpotLight.Enabled = true
end
end
end
end
game.Lighting.Changed:connect(streetLights)
