Change parts material under folder depending on its name

Hey. I need some help.

what i need is:

I got Folder udner which is model each named like “Brick” “Wood” “Fabric” etc…
basically material names

How would i make a script which would

What i got: Materials in material service all named like Brick1, Brick2, Brick 25. Wood1…Wood30
Materials are in different numbers

What i want:

  1. Go through each model depending on its name.

  2. Then rename all parts inside to the amount of materials i got so if i got 25 Brick materials then Brick 1… Brick25, if i got 35 Fabric material then Fabric1 … Fabric35

  3. Change Material of each part depending on its name

I was able to make this and it worked but i would have to manually rename all parts and so on.

for i,v in pairs(Folder) do
	v.Name = Name..i
	v.MaterialVariant = v.Name
end

Would appreciate the help as that would help me with scripting too.
I tried to work it out with table but always had issues and i want it simple

1 Like

You can set up a second for loop to get each index induvidually

for i, v in pairs(workspace.MaterialNames:GetChildren()) do
	if v:IsA("Model") then
		for i, parts in pairs(v:GetChildren()) do
			if parts:IsA("Part") then
				parts.Name = parts.Parent.Name .. i
				parts.Material = Enum.Material[parts.Parent.Name]
			end
		end
	end
end