You can write your topic however you want, but you need to answer these questions:
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
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
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)
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
@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
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.