I've decided to modify a headlight script I made to make adding cars with working head lights more simple.
Head Light script, placed in Server Script Service.
local sportscar1 = game.workspace.Cars.Sportscar1:GetChildren() local sportscar2 = game.workspace.Cars.Sportscar2:GetChildren() while true do for _, child in ipairs(sportscar1, sportscar2) do if child.Name == "Headlight" then if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then child.Material = Enum.Material.Plastic child.PointLight.Enabled = false elseif game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then child.Material = Enum.Material.Neon child.Pointlight.Enabled = true end end end wait(.1) -- The time before the loop restarts- a tenth of a second. end
I tried to use a table, but it seems to skip to the second item in the table automatically meaning the headlights on sports car1 do not work.
All of this could probably be avoided if I knew how to get the GetChildren function to search models in workspace or a folder for the part named "Headlight" Since the "Headlight" is in a model, the GetChildren doesn't detect the parts. That is what I originally tried, If I knew how to do that, not only would it make this a lot more simple, but it would cut on the time needed to add working headlights to car models.
So how can I get both car's headlights to function with a small amount of code like this so that adding more cars won't be a hassle?
Thank you in advance.