Mainly a question for the scripting pros, is this an efficient way to do what I'm trying to do? The script works perfectly fine I was just curious.
-- Services --
local Lighting = game:GetService("Lighting")
-- Directories
local Workspace_LightSources = game.Workspace:GetChildren()
-- Tables
local Table_LightSources = {}
-- Basic Values --
local Enabled_Material = Enum.Material.Neon -- Material when Source is on.
local Disabled_Material = Enum.Material.SmoothPlastic -- Material when Source is off.
-- Fill Table
for _,a in pairs (game.Workspace:GetChildren()) do -- find all Lightsources in workspace and its children
if a.Name == "LightSource" then
table.insert(Table_LightSources,a)
else
for _,b in pairs (a:GetChildren()) do
if b.Name == "LightSource" then
table.insert(Table_LightSources,b)
else
for _,c in pairs (b:GetChildren()) do
if c.Name == "LightSource" then
table.insert(Table_LightSources,c)
end
end
end
end
end
end
-- Light Sources Handler --
function LightChange(Status)
if Status == true then
for _,a in ipairs (Table_LightSources) do
a.Material = Enabled_Material
local LightChildren = a:GetChildren()
for _,b in pairs (LightChildren) do
if b.ClassName == "PointLight" or "SpotLight" or "SurfaceLight" then
b.Enabled = true
else
return
end
end
end
elseif Status == false then
for _,a in ipairs (Table_LightSources) do
a.Material = Disabled_Material
local LightChildren = a:GetChildren()
for _,b in pairs (LightChildren) do
if b.ClassName == "PointLight" or "SpotLight" or "SurfaceLight" then
b.Enabled = false
else
return
end
end
end
end
end
-- Automatic Lighting --
while true do
wait(.1)
local MinutesAfterMidnight = game.Lighting:GetMinutesAfterMidnight()
game.Lighting:SetMinutesAfterMidnight(MinutesAfterMidnight + 10)
if MinutesAfterMidnight > (18 * 60) or MinutesAfterMidnight < (5.5 * 60) then
LightChange(true)
elseif MinutesAfterMidnight < (18 * 60) or MinutesAfterMidnight > (5.5 * 60) then
LightChange(false)
end
end

7 comments
Not really you have a lot of duplicate code and why not make a table with the parts in?
I really haven't learned about tables...
They would really help for this kind of task.
do you have a link to a tutorial about tables?
http://wiki.roblox.com/?title=Table
I've updated it with a table. It works but I'm not sure if I did it entirely correctly.
That look ok, you next need to update the function LightChange as we should only be adding the parts we want to the liste meaning that this function only needs to loop through the processed table list and set its data.