So I have always wanted to make auto car lights and yet I haven't got anywhere with it yet because whenever I test it in play mode it won't turn on once it gets past 5 PM. Here's the code:
function OnChildAdded(Child)
while true do
wait(0.001)
if Child.Name == "SeatWeld" then
script.Disabled = false
for i, v in pairs(script.Parent:GetChildren()) do
if v.Name == "HLPart" then
if game.Lighting.TimeOfDay > "17:00:00" and game.Lighting.TimeOfDay < "06:30:00" then
v.Material = "Neon"
elseif game.Lighting.TimeOfDay > "06:30:00" and game.Lighting.TimeOfDay < "16:59:00" then
v.Material = "SmoothPlastic"
end
end
end
end
end
end
function OnChildRemoved(OtherChild)
if OtherChild.Name == "SeatWeld" ~= nil then
for i, v in pairs(script.Parent:GetChildren()) do
if v.Name == "HLPart" then
v.Material = "SmoothPlastic"
script.Disabled = true
wait(0.001)
script.Disabled = false
end
end
end
end
script.Parent.ChildAdded:connect(OnChildAdded)
script.Parent.ChildRemoved:connect(OnChildRemoved)
Any help on this would be much appreciated. Thank you!

1 comment
Check the comments on the answer