How do I set a custom material with script?

Can someone tell me how can I set a custom material to a part. Bing’s AI showed me this:

local materialName = "Glass Cracked"
local materialService = game:GetService("MaterialService")
materialService:SetPartMaterial(child, materialName)

This doesn’t work. Can someone help me?

1 Like

Have you set the child’s material to the base material? When you have a Material Variant, it has a base material (for example: Plastic), the part has to be same the base material. Video

The code below will set the material variant of a part. Materials are input as strings for some reason.

local part = game.Workspace.Part --your desired part

local materialVarient = game:GetService("MaterialService").Material --material in material service

part.Material = materialVarient.BaseMaterial.Name
part.MaterialVariant = materialVarient.Name

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