I am working on a script to control SpotLight, which is a children of the “Light” part in the “Body” model.
I want to use a For loop so that if there are multiple Lights in the Body, they will all light up.
However, only one of the SpotLights will work.
There are many similar questions on the forum, but using GetDescendants did not change the result.
for i ,v in pairs(seat.Parent.Body:GetChildren()) do
if v.Name == "Light" then
v.SpotLight.Enabled = not v.SpotLight.Enabled
end
end
Since this script is located within the driving GUI (LocalScript), it is cloned to the player the moment the player sits in the VehicleSeat.
Currently there are two Lights in the Body, one of which is working correctly.
Thus, I do not believe it is a path specification error.
it might be because it maybe gets destroyed, try checking on it via explorer page and and use print
maybe you’ve spelt the name ‘Light’ wrong so double check that too (you could of added a space at the end of the ‘Light’ so the script wouldn’t register it)
for i, v in pairs(seat.Parent.Body:GetChildren()) do
print(v.Name, v.ClassName, i)
if v.Name == 'Light' then
print('found light', i)
v.SpotLight.Enabled = not v.SpotLight.Enabled
end
end