Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Car Auto-Headlights Not Working - Help?

Asked by 7 years ago
Edited 7 years ago

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!

0
Check the comments on the answer RubenKan 3615 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

1
Thank you Mat! This has definitely helped me with the lights. DeanoTheDude2001 2 — 7y
0
Its fine! also you should label my comment as the answer so people know the question has been answered! Potatofoox 129 — 7y
0
I would love to label it but I have no clue how to. I tried to press up-vote but I need rep to do that. Sorry! DeanoTheDude2001 2 — 7y
1
Theres a button that says "Accept answer" below these comments. RubenKan 3615 — 7y
Ad

Answer this question