How to add a check in a module script

I would like to run a check to see if the attachment is present unfortunately this just doesn’t work out the way I would like anyone any ideas

yours sincerely,
Technical_D

---------------------- Brakes ----------------------
function module:BrakesOn(L, ClrBr, ClrB)
	for i = 1,#L do
		if string.find(L[i].Name, "BR_") then
			L[i].BrickColor = BrickColor.new(ClrBr)
			L[i].Material = Enum.Material.Neon
			L[i].Attachment.light.Enabled = true
		end
	end


end

function module:BrakesOff(L, ClrBr, ClrBrO, ClrB)
	for i = 1,#L do
		if string.find(L[i].Name, "BR_") and string.find(L[i].Name, "Back_") then
			L[i].BrickColor = BrickColor.new(ClrB)
			L[i].Material = Enum.Material.Neon
		elseif string.find(L[i].Name, "BR_") then
			L[i].BrickColor = BrickColor.new(ClrBrO)
			L[i].Material = Enum.Material.SmoothPlastic
			L[i].Attachment.light.Enabled = false
		end
	end	
end

I don’t really get your problem… mind explaining it a bit more?

how can I check that the attachment is present
because you cannot use findfirstchild on this

L[i].Attachment.light.Enabled = true

if L[i][Attachment] then
end

it gives the script a invalid argument

function module:BrakesOn(L, ClrBr, ClrB)

	for i = 1,#L do
		if string.find(L[i].Name, "BR_") then
			L[i].BrickColor = BrickColor.new(ClrBr)
			L[i].Material = Enum.Material.Neon
			if L[i][Attachment] then
				L[i].Attachment.light.Enabled = true
			end


		end
	end


end

function module:BrakesOff(L, ClrBr, ClrBrO, ClrB)

	for i = 1,#L do
		if string.find(L[i].Name, "BR_") and string.find(L[i].Name, "Back_") then
			L[i].BrickColor = BrickColor.new(ClrB)
			L[i].Material = Enum.Material.Neon
		elseif string.find(L[i].Name, "BR_") then
			L[i].BrickColor = BrickColor.new(ClrBrO)
			L[i].Material = Enum.Material.SmoothPlastic
			if L[i][Attachment] then
				L[i].Attachment.light.Enabled = false
			end


		end
	end	
end

They meant to say

L[i][“Attachment”].

Alternatively, you could use L[i]:FindFirstChild(“Attachment”). I would also reccomend giving a more precise name to the attachment holding the light, such as ‘LightAttachment’.

As @TheCraftNCreator said, I made a small grammar mistake cuz I’m on phone Xd. Just make the attachment word a string instead.