it worked after i added "and PartInModel.Name == “Light” ", now i gotta find out how to turn the light off if the battery is removed, the light is removed, or the light button is pressed again
oook… then you only want specific lights…?
As I said previously, or you name those specific lights with an unique name or use tags to select only the lights you want.
I am just gonna ask that why are you using 2 :GetDescendant()
loops? Isn’t it like the worst possible way to do almost anything?
Cause OP stated wants to iterate whole car to find the models that are named highlights and then iterate the parts inside those models to turn them into neon…
I never said this is the proper way, Im constantly insisting that this is the worst way possible, Im just replying what OP ask…
Just use tags or rename your lights with specific names and do a single loop on tags or on descendants of the model looking for names.
If its a group of lights like front are 2 and rear are 2, then use tags. Or names, whatvr
tbh, as long as it worked, idc
Name your lights with a specific name and thats it. Iterate the whole car model if you wish, just check that the name is the one you want and turn them into Neon.
How many parts should change to neon at the same time?
How many parts in total should change to neon from other buttons?
:GetDescendants()
already iterates through every part inside a model, if OP wanted to see if a a part is an ancestor of a model named HeadLights then they would never need to use 2 GetDescendants()
loops.
One way they can do it with one loop and by also seeing if the object is a descendant of an object named HeadLights is by doing this:
for _,instance in script.Parent.Parent:GetDescendants() do
if instance.Name:lower() == "light" and instance:IsA("BasePart") and instance:GetFullName():lower():find("headlight") then
instance.Material = Enum.Material.Neon
end
end
Which is much more smaller and optimized and overall a really good method.
I see that tagging would probably also not work as if OP has more than 1 car it would have the same tag and OP would have to dynamically change tags for the headlights to prevent a script from accidently turning on every single light in the game.
Isnt that what I said?..
Plus, OP wants specific lights, name the lights with different names use only one getDescendants loop and change the specific lights.
But, iterate the whole model still no efficient, just use tags, specially if are groups of lights…
what im doing is going through a folder to look for a model, then going through that model to get a part
I understand, but you can skip the looking through a model part and get on directly to looking for the part by using GetDescendant(). Unless that model of your’s is just a singular model, then just iterate over everything in that model, say if you have only 1 model named “HeadLight” then just do script.Parent.Parent.HeadLight
. I hope that made a bit sense, I am also a bit confused on what point you are trying to make here.
No not really.
A bit confused on what you mean here. I think OP has already named all the light instances as one name i.e Light
. Or am I missing something here?
I have mentioned that I assume OP would tag all lights with the same tag and if they do not change the tags dynamically to unique names, it can basically turn on every headlight of every car in the game.
could you help me with something else?
That code that you marked as the solution as we @awry_y and me stated is the worst way to achieve it…
Just use tags if you have groups of lights. Im hardly against to even do just 1 getDescendants loop. Now 2, makes no sense, unless its a model hard to handle
If your post solved it, then I don’t see any reason to not mark your post as the solution, I was just providing a better alternative.
Sure? What is the issue?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.