Change all neon parts into metal

i need it so if its neon
it changes to metal

local function Blackout()
    if BlackoutBool == false then
        BlackoutBool = true
        Generator.PowerDown:Play()
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA("PointLight") or v:IsA("SpotLight") or v:IsA("SurfaceLight") or v:IsA("") then -- here!!!
                if v.Name ~= "Ignore" then 
                    spawn(function ()
                        v.Enabled = false
                        wait(.075)
                        v.Enabled = true
                        wait(.075)
                        v.Enabled = false
                        wait(.075)
                        v.Enabled = true
                        wait(.075)
                        v.Enabled = false
                    end)
                end
            end
        end`
1 Like

What? Light objects don’t have materials.

1 Like

its a neon brick with a light inside of it, i want the full effect

1 Like

This should work if you’ve got pointlights in the neon parts. You could change the class to another light type that you’re using.

local function Blackout()
    if BlackoutBool == false then
        BlackoutBool = true
        Generator.PowerDown:Play()
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA("MeshPart") or v:IsA("Part") and v.Material == "Neon" then -- here!!!
                if v.Name ~= "Ignore"  then 
                    spawn(function ()
                      local light = v:FindFirstChildOfClass("PointLight")
                        v.Material = "Metal"
                        light.Enabled = false
                        wait(.075)
                        light.Enabled = true
                        v.Material = "Neon"
                        wait(.075)
                        light.Enabled = false
                        v.Material = "Metal"
                        wait(.075)
                        light.Enabled = true
                        v.Material = "Neon"
                        wait(.075)
                         light.Enabled = false
                        v.Material = "Metal"
                    end)
                end
            end
        end
1 Like

Its a spot light yes, but also 20:34:40.994 - ServerScriptService.BlackoutMain:37: attempt to index nil with ‘Enabled’

1 Like

change

local light = v:FindFirstChildOfClass("PointLight")

to

local light = v:FindFirstChildOfClass("SpotLight")

It was before, still the same error.

Do all neon parts have lights in them of the same type?

Oh dang, some have spot lights and some have surface lights

you can either change the script to support both spot and surface lights, or just replace the surface lights with spot lights.

How to I make it support both spotlights and surface lighting

this should do it.

local function Blackout()
    if BlackoutBool == false then
        BlackoutBool = true
        Generator.PowerDown:Play()
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA("MeshPart") or v:IsA("Part") and v.Material == "Neon" then -- here!!!
                if v.Name ~= "Ignore"  then 
                    spawn(function ()
                      local light = v:FindFirstChildOfClass("SpotLight") or v:FindFirstChildOfClass("SurfaceLight")
                        v.Material = "Metal"
                        light.Enabled = false
                        wait(.075)
                        light.Enabled = true
                        v.Material = "Neon"
                        wait(.075)
                        light.Enabled = false
                        v.Material = "Metal"
                        wait(.075)
                        light.Enabled = true
                        v.Material = "Neon"
                        wait(.075)
                         light.Enabled = false
                        v.Material = "Metal"
                    end)
                end
            end
        end

still 20:43:15.221 - ServerScriptService.BlackoutMain:37: attempt to index nil with ‘Enabled’

20:43:15.260 - Stack Begin

One of your lights probably doesn’t have a light in it. Make sure all the ones without lights have the name ignore.

Everything has a light, i checked

do any of them have pointlights?

Nope no pointlights… strange

30 ca

You have to wrap the spawned function w/
“if light then
—light flicker function here
end)”

so

local function Blackout()
    if BlackoutBool == false then
        BlackoutBool = true
        Generator.PowerDown:Play()
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA("MeshPart") or v:IsA("Part") and v.Material == "Neon" then -- here!!!
                if v.Name ~= "Ignore"  then 
                    spawn(function ()
                      local light = v:FindFirstChildOfClass("SpotLight") or v:FindFirstChildOfClass("SurfaceLight") if light then 
                        v.Material = "Metal"
                        light.Enabled = false
                        wait(.075)
                        light.Enabled = true
                        v.Material = "Neon"
                        wait(.075)
                        light.Enabled = false
                        v.Material = "Metal"
                        wait(.075)
                        light.Enabled = true
                        v.Material = "Neon"
                        wait(.075)
                         light.Enabled = false
                        v.Material = "Metal"
                    end)
                end
            end
        end

Spawn is evil!

Also, try this:

local function Blackout()
	if BlackoutBool == false then
		BlackoutBool = true
		Generator.PowerDown:Play()
		for _, Descendant in ipairs(game.Workspace:GetDescendants()) do
			if Descendant.Parent.Material == Enum.Material.Neon and Descendant:IsA("PointLight") or Descendant:IsA("SpotLight") or Descendant:IsA("SurfaceLight") then -- here!!!
				if Descendant.Name ~= "Ignore" then 
					local Parent = Descendant.Parent
					coroutine.wrap(function()
						for i = 1, 5 do
							wait(.075)
							Descendant.Enabled = not Descendant.Enabled
							Parent.Material = Enum.Material.Metal
						end
					end)()
				end
			end
		end
	end
end