:GetChildren() only goes through one child at a time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Im making a pedestrian tram crossing light where when the sensor gets touched a man looking symbol colour goes to red and the stop letters blink

  2. What is the issue?
    making the man symbol red works but making the stop letters blink doesnt work it changes the color of the meshes one at a time

  3. What solutions have you tried so far?
    i tried putting getchildren in the function like i saw on scripting helpers but it doesnt work

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Sensor = script.Parent.Sensor
local Man = script.Parent.Blink
local Stop = script.Parent.Lettres:GetChildren()

Sensor.Touched:Connect(function()
	Man.BrickColor = BrickColor.new("Really red")
	while true do
		for i, Stop in pairs(Stop) do
			Stop.BrickColor = BrickColor.new("Really red")
			wait(1)
			Stop.BrickColor = BrickColor.new("Black")
		end
	end
end)

robloxapp-20230726-1707444.wmv (1.3 MB)

1 Like
while true do
	for i, Stop in pairs(Stop) do
		Stop.BrickColor = BrickColor.new("Really red")
	end
	wait(1)
	for i, Stop in pairs(Stop) do
		Stop.BrickColor = BrickColor.new("Black")
	end
	wait(1)
end
1 Like

@bytesleuth’s solution should work but another method of going through with this could be with coroutines. This creates a new thread for each letter allowing all letters to change simultaneously.

	for i, Stop in pairs(Stop) do
		coroutine.wrap(function()
			while true do 
				Stop.BrickColor = BrickColor.new("Really red")
				wait(1)
				Stop.BrickColor = BrickColor.new("Black")
			end
		end)()
	end
	

What do you mean simulatenously it’s the same? Also, you’re creating a new thread everytime loop runs with no delay.

Your method works. I was just talking about threads in general.

also your right about the delay thing I forgot to flip the while true do into the coroutine.

for loops, and about any loop in general, will always iterate through one object at a time, which there is not very much you can do about that.

However, I would not Recommend you use a loop for this, but rather RunService, or better yet, the Client in general when it comes to these details, which if taken care of by the Server, can slow down your game, so the client would be a safer, and more convienient place for this.

The Method I provided here should also be more convenient, and should not cause any isseus as far as im aware of:

local Sequence = {BrickColor.new("Really red"), BrickColor.new("Black")}
-- This will keep track of the Order in which the coors will switch in
local Current = os.clock() -- CPU Uptime (used to high presicion stuff)
-- Here it is used to record the elapsed time
local Delay = 1 -- The Time to wait for Changes
local State = 0 -- The Current Location in our Sequence

local SequenceLimit = (#Sequence + 1) -- The Number where the Sequence will reset

local function Set(Color) -- Function to Apply Color to Objects
	for _, v in Stop do
        if not v:IsA("BasePart") then continue end
        -- this is to ensure we get the correct object to avoid any errors
		v.BrickColor = Color
	end
end



RunService.Heartbeat:Connect(function() -- Will run every frame
    local elapsed = os.clock() - Current -- elapsed time
    if elapsed < Delay then return end -- stops if limit has not been reached
    
    Current = os.clock() -- restarts the time
    State = math.max(1, (State + 1) % SequenceLimit) 
    -- Adds 1 to the Sequence, if number goes over Sequence Limit
    -- It will reset back to 0, math.max() will ensure it goes to 1
    -- to avoid errors
    
    Set(Sequence[State]) -- Applies Color using Current State
end)

This method will not yield like the others, it will instead check for how much time has passed in order to apply the BrickColor that this contained by the Sequence.