Union material/colour change script not working properly

So I’m working for my friend’s game, and I’m trying to create a winter theme for the map. I’m bascially just trying to change all parts/meshparts/unions that have the grass material change their colour and material.

Here is the script.

for _,v in pairs(workspace:GetDescendants()) do
	if (v:IsA'MeshPart') or (v:IsA'Union') or (v:IsA'Part') then
		if (v.Material == Enum.Material.Grass) or (v.Parent.Name == 'Path') then
			pcall(function()
				v.UsePartColor = true;
			end);
			v.Material = Enum.Material.Snow;
			v.BrickColor = BrickColor.new'Institutional white';
		end;
	end;
end;

My problem is that the script works completely fine for parts and meshparts, but doesn’t work for unions even though they all have UsePartColor enabled. I see absolutely no errors in the developer console, and I currently have no idea what the solution to this is. I can edit the colour and material manually in edit mode.

Edit Mode:

When Ran:


(Unions are not affected by the script when parts and meshparts are)

1 Like

Try using if v:IsA('BasePart') then instead. I think unions’ ClassNames are “UnionOperations” as well. Checking if it’s a BasePart will work for meshes, parts, wedge parts, trusses, unions etc.

1 Like

Completely forgot about that. I should’ve double checked the classname. Thank you.

1 Like