Hello, can please someone help me ??. I’m trying to turn on a “SurfaceLight” when the Time goes after 18. But it says “Workspace.GameWorld.Streetdeko.Lamps.Script:12: attempt to index nil with ‘Part’”.
Script ‘Workspace.GameWorld.Streetdeko.Lamps.Script’, Line 12.
Explorer:
Script:
while true do
wait(2.5)
for i,v in pairs(script.Parent.Parent.Lamps.Lantern:GetChildren()) do
wait(2.5)
local light = v:FindFirstChild("SurfaceLight")
if light then
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
light.Part.SurfaceLight.Enabled = false
print("light")
end
else if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
light.Part.SurfaceLight.Enabled = true
print("light")
end
end
end
end
Hm Okey. But now it says i forgot to close the line “Error: (10,38) Syntax error: Expected ‘end’ (to close ‘do’ at line 3), got ; did you forget to close ‘then’ at line 9?”
while true do
wait(2.5)
for i,v in pairs(script.Parent.Parent.Lamps.Lantern:GetChildren()) do
wait(2.5)
local light = v:FindFirstChild("SurfaceLight")
if light then
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
light:FindFirstChild("Part").SurfaceLight.Enabled = false
elseif game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
light:FindFirstChild("Part").SurfaceLight.Enabled = true
end
end
end
end
I’m assuming this error is because you have light already as the surface light and are trying to find a light and a surface light under the surface light. Instead of
Workspace.GameWorld.Streetdeko.Lamps.Script:12: attempt to index nil with 'Enabled'
Script 'Workspace.GameWorld.Streetdeko.Lamps.Script', Line 12 - Studio - Script:12
Script:
while true do
wait(2.5)
for i,v in pairs(script.Parent.Parent.Lamps.Lantern:GetChildren()) do
wait(2.5)
local light = v:FindFirstChild("SurfaceLight")
if light then
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
light.Enabled = true
print("light")
end
else if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
light.Enabled = true
print("light")
end
end
end
end
this works for me though?
this is the script I used:
while true do
wait(2.5)
for i,v in pairs(script.Parent.Parent.Lamps.Lantern:GetChildren()) do
wait(2.5)
local light = v:FindFirstChild("SurfaceLight")
if light then
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
light.Enabled = false
print("light")
end
else if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
light.Enabled = true
print("light")
end
end
end
end