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!
I looked into this as it baffled me as to why you can't use less than and more than. After looking through the functions of lighting i discovered minutes after midnight.
if you replace your less than and greater than with a script like
part = game.Workspace.Part while wait(.1) do if game.Lighting:GetMinutesAfterMidnight() < 390 or game.Lighting:GetMinutesAfterMidnight() > 1020 then part.Material = "Neon" else part.Material = "SmoothPlastic" end end
it worked for me so hope it does for you too.