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

CanCollide

BasePart

bool

The CanCollide property determines whether a part will physically interact with other parts. When disabled, other parts can pass through the brick uninterrupted. Parts used for decoration usually have CanCollide disabled, as they need not be considered by the physics engine.

If a part is not /BasePart/Anchored and has CanCollide disabled, it may fall out of the world to be eventually destroyed by /Workspace/FallenPartsDestroyHeight. Therefore, it is usually desirable to anchor such parts or join them to another part that is anchored so that they don’t fall out of the level. You can also use an object like /BodyPosition or /BodyForce to prevent falling out of the level entirely.

Even when CanCollide is disabled, parts may still fire the /BasePart/Touched event (as well the other parts touching them). In addition, a part allow other parts to pass through even if CanCollide is enabled if their collision groups are not set to collide with each other. Part collision groups are managed by /PhysicsService.


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()