Apply variant issue

I’m making a script to apply the material variant to all parts in workspace but it seems not to be applying the variant, could someone fix the script.

image

image

image

	local materialToVariant = {
		[Enum.Material.Plastic] = MaterialService.PlasticVariant.Name,
		[Enum.Material.SmoothPlastic] = MaterialService.SmoothPlasticVariant.Name,
		[Enum.Material.Metal] = MaterialService.MetalVariant.Name,
		[Enum.Material.Fabric] = MaterialService.FabricVariant.Name,
	}
	
	for _, part in pairs(game.Workspace:GetDescendants()) do if part:IsA("BasePart") then local variant = materialToVariant[part.Material] if variant then part.MaterialVariant = variant end end end

Not an expert on MaterialService but looking at the documentation - MaterialService | Documentation - Roblox Creator Hub I believe your mapping table is incorrect

	local materialToVariant = {
		[Enum.Material.Plastic] = MaterialService.PlasticVariant.Name,
		[Enum.Material.SmoothPlastic] = MaterialService.SmoothPlasticVariant.Name,
		[Enum.Material.Metal] = MaterialService.MetalVariant.Name,
		[Enum.Material.Fabric] = MaterialService.FabricVariant.Name,
	}

should be

local materialToVariant = {
    [Enum.Material.Plastic] = MaterialService.PlasticName,
    [Enum.Material.SmoothPlastic] = MaterialService.SmoothPlasticName,
    [Enum.Material.Metal] = MaterialService.MetalName,
    [Enum.Material.Fabric] = MaterialService.FabricName,
}
1 Like

Thank you so much for fixing the code!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.