Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Car Auto-Headlights Not Working - Help?

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

0

Check the comments on the answer

1 answer

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.

4 comments

1

Thank you Mat! This has definitely helped me with the lights.

0

Its fine! also you should label my comment as the answer so people know the question has been answered!

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!

1

Theres a button that says "Accept answer" below these comments.

This discussion is preserved as it was. New answers, comments, and votes are closed.