Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing the Material and Color of BaseParts, MeshParts, and UnionOperations based on name?

Hey, I need help changing the Material and Color of BaseParts, MeshParts, and UnionOperations based on their names. I currently went about the idea by doing this:

for _, Child in pairs(workspace:GetDescendants()) do
	if Child:IsA("BasePart") or Child:IsA("MeshPart") or Child:IsA("UnionOperation") then
		local String = Child.Name
				
		if String:find("Wood") then
			Child.Material = Enum.Material.Wood
		elseif String:find("WoodPlanks") then
			Child.Material = Enum.Material.WoodPlanks
		end
	end
end

I had more materials to this script, but I removed it for the sake of it being short, plus you already get the gist of it.

The issue with this script is that if the Child's name is WoodPlank, it will convert the Child's Material to Wood. Because of this, using this idea to achieve the same idea but with Color will be useless considering how many of them share the same string. Do you guys have any ideas on how I could go about this idea?

1 answer

✓ Accepted answer
local wood, plank = ("Wood"):lower(), ("Plank"):lower()

for _, Child in pairs(workspace:GetDescendants()) do
  if Child:IsA("BasePart") or Child:IsA("MeshPart") or Child:IsA("UnionOperation") then
     local String = (Child.Name):lower()
     if String:find(wood) then
         Child.Material = Enum.Material.Wood
     if String:find(wood) and String:find(plank) then
         Child.Material = Enum.Material.WoodPlanks
        end
      end
   end
end

Hope this helps.

This discussion is preserved as it was. New answers, comments, and votes are closed.