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

Transparency

BasePart

float

The Transparency property controls the visibility of a part on a scale of 0 to 1, where 0 is completely visible (opaque), and a value of 1 is completely invisible (not rendered at all).

BasePart/Reflectance can reduce the overall transparency of a brick if set to a value close to 1.

While fully transparent parts are not rendered at all, partially transparent objects have some significant rendering costs. Having many translucent parts may slow down the game’s performance.

When transparent parts overlap, render order can act unpredictable - try to keep semi-transparent parts from overlapping to avoid this.

The BasePart/LocalTransparencyModifier is a multiplier to Transparency that is only visible to the local client.


Code Samples


Fade Door

This code sample shows how a part can fade away when touched by a Humanoid then reappear a moment after to create a passable door.

-- Paste into a Script inside a tall part
local part = script.Parent

local OPEN_TIME = 1

-- Can the door be opened at the moment?
local debounce = false

local function open()
	part.CanCollide = false
	part.Transparency = 0.7
	part.BrickColor = BrickColor.new("Black")
end

local function close()
	part.CanCollide = true
	part.Transparency = 0
	part.BrickColor = BrickColor.new("Bright blue")
end

local function onTouch(part)
	-- If the door was already open, do nothing
	if debounce then print("D") return end
	
	-- Check if touched by a Humanoid
	local human = part.Parent:FindFirstChildOfClass("Humanoid")
	if not human then print("not human") return end

	-- Perform the door opening sequence	
	debounce = true
	open()
	wait(OPEN_TIME)
	close()
	debounce = false	
end

part.Touched:Connect(onTouch)
close()

X-Ray Vision

This code sample gives the local client X-ray vision using LocalTransparencyModifier. It allows the player to see through all parts in the Workspace, which are found using recursion.

-- X-ray vision: see through everything!

local function makeXRayPart(part)
	-- LocalTransparencyModifier will make parts see-through but only for the local
	-- client, and it won't replicate to the server
	part.LocalTransparencyModifier = .5 
end

-- This function uses recursion to search for parts in the game
local function recurseForParts(object)
	-- Did we find a part that isn't 
	if object:IsA("BasePart") then
		makeXRayPart(object)
	end
	
	-- Stop if this object has a Humanoid - we don't want to see-through players! 
	if object:FindFirstChildOfClass("Humanoid") then return end
	
	-- Check the object's children for more parts
	for _, child in pairs(object:GetChildren()) do
		recurseForParts(child)
	end
end

recurseForParts(workspace)