Help with changing union color and material

I am making a strategy game, and I am making a tank corroding when it dies. Every part changes it color and material (except tracks, they mustnt), but unionned part does not (I have UsePartColor on).

My script:

local tank = script.Parent
local material = Enum.Material.CorrodedMetal
local humanoid = tank:FindFirstChild("Tank")
local color = Color3.fromRGB(80, 58, 23)

local corrodeNames = {
	"Hull",
	"Armor",
	"Turret",
	"Cannon"
}

humanoid.Changed:Connect(function(property)
	if property == "Health" and humanoid.Health <= 0 then
		for _, part in pairs(tank:GetDescendants()) do
			if part:IsA("Part") then
				if table.find(corrodeNames, part.Name) then
					part.Material = material
					part.Color = color
				end
			end
		end
	end
end)

Photo of tank in explorer and selected union that does not changes.
sad

Photo of tank after it dies (again, union does not changes)
sdf
Thanks in advance!

Your code checks if the object is a Part, not if it is a Part or Union

just change this line to this:

if part:IsA("Part") or v:IsA("UnionOperation") then
1 Like

Thanks, haven’t seen this before! :sweat_smile: