PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Material

BasePart

Material

The Material property allows a builder to set a part’s texture and default physical properties (in the case that /BasePart/CustomPhysicalProperties is unset). The default Plastic material has a very light texture, and the SmoothPlastic material has no texture at all. Some material textures like DiamondPlate and Granite have very visible textures. Each material’s texture reflects sunlight differently, especially Foil.

Setting this property then enabling /BasePart/CustomPhysicalProperties will use the default physical properties of a material. For instance, DiamondPlate is a very dense material while Wood is very light. A part’s density determines whether it will float in terrain water.

The Glass material changes rendering behavior on moderate graphics settings. It applies a bit of reflectiveness (similar to /BasePart/Reflectance) and perspective distortion. The effect is especially pronounced on sphere-shaped parts (set /BasePart/Shape to Ball). Semitransparent objects and Glass parts behind Glass are not visible.


Code Samples


Part Anchored Toggle

This code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).

local part = script.Parent

-- Create a ClickDetector so we can tell when the part is clicked 
local cd = Instance.new("ClickDetector", part)

-- This function updates how the part looks based on its Anchored state
local function updateVisuals()
	if part.Anchored then
		-- When the part is anchored...
		part.BrickColor = BrickColor.new("Bright red")
		part.Material = Enum.Material.DiamondPlate
	else
		-- When the part is unanchored...
		part.BrickColor = BrickColor.new("Bright yellow")
		part.Material = Enum.Material.Wood
	end
end

local function onToggle()
	-- Toggle the anchored property
	part.Anchored = not part.Anchored
	
	-- Update visual state of the brick
	updateVisuals()
end

-- Update, then start listening for clicks
updateVisuals()
cd.MouseClick:connect(onToggle)