How would i edit a property of every single child in a folder? I'm just trying to make one script for all of my traffic lights, but it will only edit the first child of the folder.

okworkspace = game:GetService("Workspace")

for i,v in pairs(okworkspace:WaitForChild("Traffic Lights"):GetChildren()) do
    if v:IsA("Model") then
        okworkspace:WaitForChild("Traffic Lights"):WaitForChild(v.Name)
        while wait(15) do
            v.SET1_1.SIG1.G.led.Enabled = false
            v.SET1_1.SIG2.G.led.Enabled = false
            v.SET1_1.SIG1.Y.led.Enabled = true
            v.SET1_1.SIG2.Y.led.Enabled = true
            
            wait(2)
            
            v.SET1_2.SIG1.G.led.Enabled = false
            v.SET1_2.SIG2.G.led.Enabled = false
            v.SET1_2.SIG1.Y.led.Enabled = true
            v.SET1_2.SIG2.Y.led.Enabled = true
        end
    end
end

I removed most of the actual script because it is just repetitive lines of code editing .Enabled with some wait()'s

Asking in #scripting-questions on the discord has led to nothing working and my attempts have had no avail to trying to fix this problem. Any help would be appreciated.

2 comments

0

There's probably multiple objects named TrafficLight and the WaitForChild chooses a random TrafficLight to edit.

0

Each lightset is named "Traffic Light" and their in a folder called "Traffic Lights", I tried removing all the waitforchild() and it did nothing.