GetDescendants Only Targets One Part At a Time Instead of All Parts?

Hey Guys, I am running into a new issue with GetDescendants(). I’ve never had this issue before and I am not sure why this is happening or how to solve it.
What I am trying to accomplish is pretty basic. There are three parts total with the name “LightPart” and using GetDescendants(); I would like to change the color of said parts to red. However, when I run the script, it only changes the color of one part at a time instead of simultaneously. Why? How? Any Soluations?
Same thing occurs when I use GetChildren() aswell.

Here is the script.

local lights = script.Parent.Parent:GetDescendants()

for i, flicker in ipairs(lights) do
	
	if flicker:IsA("BasePart") and flicker.Name == "LightPart" then
		flicker.BrickColor = BrickColor.new("Black")
		wait(5)
		flicker.BrickColor = BrickColor.new("Red")
	end
end

Update: So the issue to my first problem was solved. I was told by @Befogs that everytime a part changes color; we wait 5 seconds for the next part to change color. The script was updated to the following.

local lights = script.Parent.Parent:GetDescendants()


for i, flicker in ipairs(lights) do
	if flicker:IsA("BasePart") and flicker.Name == "LightPart" then
		flicker.BrickColor = BrickColor.new("Black")
	end
end

wait(2)

for i, flicker in ipairs(lights) do
	if flicker:IsA("BasePart") and flicker.Name == "LightPart" then
		flicker.BrickColor = BrickColor.new("Red")
	end
end

However, a new issue has occured. All parts are changing to the color white the second the game is being runned. This makes it extremely odd due to the fact that the script is supposed to making the color of the parts red, not white. Again, why? How? Any solutions?

1 Like

It’s happening because of the wait() function that you’re using inside the for loop. The wait() function pauses the execution of the script for the specified number of seconds, causing the script to change the color of one part and then wait for 5 seconds before moving on to the next part. This means that the color change for each part occurs one after the other instead of simultaneously.

2 Likes

“Red” isn’t a valid BrickColor so it’s just defaulting to the light gray color.
https://create.roblox.com/docs/reference/engine/datatypes/BrickColor

Might be easier to just use Color3 instead of BrickColor

flicker.Color = Color3.new(1, 0, 0)
1 Like

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