I was trying to make the red light flash in all models. However for some reason, it just flashes it in one model. The models are all inside the “Appearance” folder, they all have the same name, “Signal”, and all have the red light part inside of them.
for _, Signal in pairs (script.Parent.Appearance:GetChildren())
while true do
Signal.Lights.Red.Transparency = 0
wait(0.9)
Signal.Lights.Red.Transparency = 0.9
wait(0.9)
end
end
Just use task.spawn(function() to create new thread
local debounceTable = {}
while true do
for _, Signal in pairs (script.Parent.Appearance:GetChildren())
task.spawn(function()
if not debounceTable[Signal] then
debounceTable[Signal] = true
Signal.Lights.Red.Transparency = 0
task.wait(0.9)
Signal.Lights.Red.Transparency = 0.9
task.wait(0.9)
debounceTable[Signal] = nil
end
end)
end
end
And what task.spawn(function() does is that it makes new thread as I’ve already said so basically if you have any yield inside it won’t stop the code from executing
local time = os.time()
task.wait(2)
print(os.time() - time)
local time = os.time()
task.spawn(function()
task.wait(2)
end)
print(time - os.time())
for _, Signal in pairs (script.Parent.Appearance:GetChildren())
coroutine.create(function()
while true do
Signal.Lights.Red.Transparency = 0
task.wait(0.9)
Signal.Lights.Red.Transparency = 0.9
task.wait(0.9)
end
end)
end
for _, Signal in pairs (script.Parent.Appearance:GetChildren())
while true do
Signal.Lights.Red.Transparency = 0
wait(0.9)
Signal.Lights.Red.Transparency = 0.9
wait(0.9)
break
end
end
You are kinda right sorry I am not that good at explaining these things if you really want to learn more about them take a look on DevHub or here on devforum.