Enum.MaterialVariant instead of Enum.Material

I’m trying to change a material with a script using this code:

– Function to change the material to plastic
local function SetPlasticMaterial()
if part:IsA(“BasePart”) then
part.Material = Enum.Material.Plastic
end
end

Whole script:

Summary
-- Get references to the part and the PointLight object
local part = script.Parent
local pointLight = part:FindFirstChild("PointLight")

-- Function to change the material to plastic
local function SetPlasticMaterial()
	if part:IsA("BasePart") then
		part.Material = Enum.Material.Plastic
	end
end

-- Function to change the material to a custom material (e.g., Neon)
local function SetCustomMaterial()
	if part:IsA("BasePart") then
		part.Material = Enum.Material.Neon
	end
end

-- Function to toggle the PointLight
local function TogglePointLight()
	if pointLight and pointLight:IsA("PointLight") then
		pointLight.Enabled = not pointLight.Enabled
	end
end

-- Function to handle the flicker effect
local function Flicker()
	while true do
		wait(math.random(0.5, 2))  -- Wait for a random interval (1-5 seconds)

		SetPlasticMaterial()    -- Change material to plastic
		TogglePointLight()      -- Toggle the PointLight
		wait(0.1)               -- Wait for a short duration
		SetCustomMaterial()     -- Change material back to custom
		TogglePointLight()      -- Toggle the PointLight
	end
end

-- Start the flicker effect
Flicker()

I’ve tried to change it to a MaterialVariant instead of just Material by adding part.MaterialVariant = Enum.MaterialVariant.[InsertMaterialHere] beneath the first Enum.Material, or Instance.new(“Material”) with its rbxassetID, but no luck.

Is it even possible to that?

1 Like

To use a MaterialVariant, the Instance must be under MaterialService. To set it to a bart, simply do

part.MaterialVariant = "MaterialVariantName"
1 Like