Helipad lights not blinking. (Looping issue)

Um, hello. So I am a builder but currently messing up with some scripts. It’s been already a while since I scripted last time so I’ve forgot all the stuff.

What I need here is to create a script that will let me pick multiple parts (With the same name) and then loop them(Change color), the problem is I also need to select a light object which is in each of the parts I selected earlier and to loop it with the color changing part at the same time.
Kinda like just a part which changes color along with a light which blinks in the same time.

Here is what I tried so far:

while true do
	for i,v in pairs(game.Workspace.HelipadLight:GetChildren()) do
		local part = v:FindFirstChild("Part")
		local light = part:FindFirstChild("PointLight")
		light.Enabled = false
		part.Color = Color3.fromRGB(70, 70, 70)
		wait(1)
		light.Enabled = true
		part.Color = Color3.fromRGB(255, 90, 90)
		wait(0.1)
		light.Enabled = false
		part.Color = Color3.fromRGB(70, 70, 70)
		wait(0.1)
		light.Enabled = true
		part.Color = Color3.fromRGB(255, 90, 90)
		wait(0.1)
	end
end

Thanks for reading or any feedback!

Are there any errors? What happens currently?

Workspace.LightBlink:4: attempt to index nil with ‘FindFirstChild’

I think the problem is in the code, as I cant select a object in object like that.

local part = v:FindFirstChild("Part")

This line is returning nil. Can you try removing the FindFirstChild(“Part”) bit (so it would just be

local part = v

then tell me how it goes?

The error is in the next line
local light = part:FindFirstChild(“PointLight”)

I am aware, but what is nil is the part, which is why I asked them to change it

That line isn’t the one causing issues as I said.
And I cant remove the :FinfirstChild(“Part”) In the line above error as it will not return anything

can you send me a picture of the explorer window?

LightBlink - Roblox Studio 01.10.2021 17_55_10
Sorry for bad quality, I am searching for the best screen capture program.

Ok, so I was right earlier,

Replace

local part = v:FindFirstChild("Part")

with

local part = v

v is already the part, so searching for it again returns nil (hence the error)

1 Like

The :GetChildren() method let’s you traverse the contents of HelipadLight, in this case the parts in the folder. Therefore the values assigned to v will be the part instances in the folder. Part is nil because the part instances have no child called part (because local part is already the part instances). You need to do what @PoppyandNeivaarecute says for it to accurately point to the part instances in local light.

So I did some changes:
LightBlink - Roblox Studio 01.10.2021 18_08_42
LightBlink - Roblox Studio 01.10.2021 18_08_35
And I get an error:
PointLight is not a valid member of Part “Workspace.HelipadLight.Part”

Do you need to pass the “Bulb” thing with the get children?

(im going to sleep, Complicated can you please take over?)

1 Like

What do you mean? I need to pass it so I adress all objects(“Bulb”) In the folder

Try removing the “Bulb” from GetChildren. GetChildren automatically creates an array of every object in an instance so I do not believe Bulb is necessary. Everything else looks fine, is there maybe another instance called “HelipadLight” in workspace?

You can then place the for loop code body in a if statement to check if v is a part instance (I see the script is also a part of the folder).

I totally forgot to check if there is another object called the same. The code actually works now, but the script loops each light separately, like it loops light 1 then it does the same with light 2 and so on. How can I change it so all the lights blink at the same time?

Also the script isnt in in the folder, its part of the workspace.

I am awake now. I will rewrite the script so it works correctly!

local function alternate(status)
	for i, v in pairs(game.Workspace.HelipadLight:GetChildren()) do
		v.PointLight.Enabled = status
		if status then
			v.Color = Color3.fromRGB(255,90,90)
		else
			v.Color = Color3.fromRGB(70, 70 , 70)	
		end
			
	end
end

while true do
	alternate(false)
	wait(1)
	alternate(true)
	wait(0.1)
	alternate(false)
	wait(0.1)
	alternate(true)
	wait(0.1)
end	

This SHOULD work and achieve what you want. If not, let me know!

I think that will still have them turn on and off one at a time and not all at once (since the for loop is still iterating through the parts). The easiest solution that I can think of would be to put a script in each part and have it run simultaneously but IDK how that would affect performance heh.

The delay between them would be so small it wouldn’t really matter.

Can you still give the script I provided a try and tell me how it goes?