:GetDescendants() doesn't go through everthing at once

I’ve made a script that supposes to change 3 unions brick color and play a sound all the same time except it does it one by one

I’ve tried using coroutine.wrap but i doesnt make a difference

["E"] = function()
				for _,v in Train:GetDescendants() do
						if v:IsA("BasePart") and v.Name == "DoorLed" then
							--make the function below change v part and play sound at the same time
							v.BrickColor = BrickColor.new("Crimson")
							v.Sound:Play()
							task.wait(v.Sound.TimeLength)
							v.BrickColor = BrickColor.new("Institutional white")
				    end	
				end
			end,

Use

["E"] = function()
				for i,v in Train:GetDescendants() do
						if v:IsA("BasePart") and v.Name == "DoorLed" then
							--make the function below change v part and play sound at the same time
							v.BrickColor = BrickColor.new("Crimson")
							v.Sound:Play()
							task.wait(v.Sound.TimeLength)
							v.BrickColor = BrickColor.new("Institutional white")
				    end	
				end
			end,

It plays them one by one because of the task.wait(v.Sound.TimeLength). You should add task.spawn() or coroutine.wrap in the right place to fix this issue.

["E"] = function()
				for _,v in Train:GetDescendants() do
						if v:IsA("BasePart") and v.Name == "DoorLed" then
							--make the function below change v part and play sound at the same time
							v.BrickColor = BrickColor.new("Crimson")
							v.Sound:Play()
                            task.spawn(function()
	                            task.wait(v.Sound.TimeLength)
						        v.BrickColor = BrickColor.new("Institutional white")
                            end)
						end
				    end	
				end
			end,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.