0

# Won't get all the children in the model [Light Arrow]??

My script is suppose to set the transparency to 0 and 1 for all the parts in [light arrow] but it only does 1 random part in the model

game.ReplicatedStorage["Light Settings"]["Left Lights"].OnServerEvent:Connect(function()

local Switch = script.Parent.Switch
local ConLights = script.Parent["Light Arrow"]:WaitForChild(script.Parent["Light Arrow"].LPart, 12)
while Switch.Value == true do
for _, ConLights in ipairs(script.Parent["Light Arrow"]:GetChildren()) do
ConLights.Transparency = 0
wait(1)
ConLights.Transparency = 1

end
end
end)

0
At the same time or one by one? Also you're overwriting ConLights in Line 7, maybe you're trying to edit the ConLights in Line 4 T3_MasterGamer 2142 — 1mo
0
At the same time. on line 7 I thought that is the way to get all the parts in the model [Light Arrow] 666_brithday 103 — 1mo

1

To change all parts at the same time, use a coroutine. Wrap Lines 9-11 in either coroutine.wrap() or task.spawn() (recommended).

For this I'm using @aleandroblingo's answer.

game.ReplicatedStorage["Light Settings"]["Left Lights"].OnServerEvent:Connect(function()
local Switch = script.Parent.Switch
local LightArrow = script.Parent["Light Arrow"]

while Switch.Value == true do

for _, ConLights in ipairs(LightArrow:GetChildren()) do
ConLights.Transparency = 0
ConLights.Transparency = 1
end)
end
end
end)

0
Thx for ur help 666_brithday 103 — 1mo
0
Wait there is a minor bug I am getting now when I changed the wait time to 4 it doesn't wait 4 seconds it just keeps doing it every second 666_brithday 103 — 1mo
0
line 6 or 11? you should change line 6 not 11 T3_MasterGamer 2142 — 29d
0
OK THX 666_brithday 103 — 29d
0

If I'm correct, this only returns one instance of the specified child, meaning that your ConLights variable only refers to one part in the "Light Arrow" object.

To fix this issue, try to replace the WaitForChild method with the GetChildren method, which will return a table containing all the children of the "Light Arrow" object. Then, you can iterate over this table using a for loop and apply the transparency changes to each part individually.

Try this script:

game.ReplicatedStorage["Light Settings"]["Left Lights"].OnServerEvent:Connect(function()
local Switch = script.Parent.Switch
local LightArrow = script.Parent["Light Arrow"]

while Switch.Value == true do