Error: Workspace.Map.LampPost.Script:53: attempt to index a nil value
Automatic open and close LamPost, WHY "attempt to index a nil value"??
local oh,om = 6,30 -- Open Time (hours,minutes)
local ch,cm = 18,00 -- Close Time (hours, minutes)
local l = game:service("Lighting")
if (om == nil) then om = 0 end
if (cm == nil) then cm = 0 end
function TimeChanged(lf,lr)
local ot = (oh + (om/60)) * 60
local ct = (ch + (cm/60)) * 60
if (ot < ct) then
if (l:GetMinutesAfterMidnight() >= ot) and (l:GetMinutesAfterMidnight() <= ct) then
lf.Enabled = false
lf.Parent.BrickColor = BrickColor.Black()
lf.Parent.Material = Enum.Material.SmoothPlastic
-------------------------------------------------
lr.Enabled = false
lr.Parent.BrickColor = BrickColor.Black()
lr.Parent.Material = Enum.Material.SmoothPlastic
else
lf.Enabled = true
lf.Parent.BrickColor = BrickColor.White()
lf.Parent.Material = "Neon"
-------------------------------------------------
lr.Enabled = true
lr.Parent.BrickColor = BrickColor.White()
lr.Parent.Material = "Neon"
end
elseif (ot > ct) then
if (l:GetMinutesAfterMidnight() >= ot) or (l:GetMinutesAfterMidnight() <= ct) then
lf.Enabled = false
lf.Parent.BrickColor = BrickColor.Black()
lf.Parent.Material = Enum.Material.SmoothPlastic
-------------------------------------------------
lr.Enabled = false
lr.Parent.BrickColor = BrickColor.Black()
lr.Parent.Material = Enum.Material.SmoothPlastic
else
lf.Enabled = true
lf.Parent.BrickColor = BrickColor.White()
lf.Parent.Material = "Neon"
-------------------------------------------------
lr.Enabled = true
lr.Parent.BrickColor = BrickColor.White()
lr.Parent.Material = "Neon"
end
else
print("TimeChange 'LampPostScript' error. ")
end
end
for i,v in pairs(script.Parent:GetChildren()) do
local lf = v:FindFirstChild("Left").Light.SurfaceLight
local lr = v:FindFirstChild("Right").Light.SurfaceLight
TimeChanged(lf,lr)
game.Lighting.Changed:connect(function(property)
if (property == "TimeOfDay") then
TimeChanged(lf,lr)
end
end)
end

1 comment
Thanks it is works!