GetPartsObscuringTarget change material but needs array?

Hi! I am making a script that whenever the character is behind a wall, the wall turns into glass but when the character leaves, it returns to its original material.

Although it does work, it only works with 1 part material, creating all sort of issues…like giving the one stored material to all of the affected parts.

I got stuck while trying to use table.insert to make an array so each part would have an identifier. HELP!

local partMaterial = {}
local glassMaterial = Enum.Material.Glass

	for i, part in pairs(obscuringParts) do 
		part.Material = partMaterial

	obscuringParts = Camera:GetPartsObscuringTarget({rootPart.CFrame.p},excludefromObscure)

	for i, part in pairs(obscuringParts) do
		partMaterial = part.Material	
		part.Material = glassMaterial

Thank you in advance!

You are setting a table to a Material. You should do table.insert() to insert it and partMaterial[table.find(material)] to retrieve it.