Collisions

Collision events automatically occur when two BaseParts touch or stop touching in the 3D world. Through collision filtering techniques, you can control which physical assemblies collide with others.

Collision Events

Collision events occur when two BaseParts touch or stop touching in the 3D world. You can detect these collisions through the Touched and TouchEnded events which occur regardless of either part's CanCollide property value. When considering collision handling on parts, note the following:

Touched

The Touched event fires when a BasePart comes in contact with another, or with a Terrain voxel. It only fires as a result of physical simulation and will not fire when the part's Position or CFrame is explicitly set such that it intersects another part or voxel.

The following code pattern shows how the Touched event can be connected to a custom onTouched() function. Note that the event sends the otherPart argument to the function, indicating the other part involved in the collision.

Part Collision

local part = workspace.Part
local function onTouched(otherPart)
print(part.Name .. " collided with " .. otherPart.Name)
end
part.Touched:Connect(onTouched)

Note that the Touched event can fire multiple times in quick succession based on subtle physical collisions, such as when a moving object "settles" into a resting position or when a collision involves a multi‑part model. To avoid triggering more Touched events than necessary, you can implement a simple debounce system which enforces a "cooldown" period through an instance attribute.

Part Collision With Cooldown

local part = workspace.Part
local COOLDOWN_TIME = 1
local function onTouched(otherPart)
if not part:GetAttribute("Touched") then
print(part.Name .. " collided with " .. otherPart.Name)
part:SetAttribute("Touched", true) -- Set attribute to true
task.wait(COOLDOWN_TIME) -- Wait for cooldown duration
part:SetAttribute("Touched", false) -- Reset attribute
end
end
part.Touched:Connect(onTouched)

TouchEnded

The TouchEnded event fires when the entire collision bounds of a BasePart exits the bounds of another BasePart or a filled Terrain voxel. It only fires as a result of physical simulation and will not fire when the part's Position or CFrame is explicitly set such that it stops intersecting another part or voxel.

The following code pattern shows how the TouchEnded event can be connected to a custom onTouchEnded() function. Like Touched, the event sends the otherPart argument to the function, indicating the other part involved.

Non-Collision Detection

local part = workspace.Part
local function onTouchEnded(otherPart)
print(part.Name .. " is no longer touching " .. otherPart.Name)
end
part.TouchEnded:Connect(onTouchEnded)

Model Collisions

Models such as player characters contain multiple parts. Since a Model object as a whole cannot be connected to the Touched or TouchEnded events, you'll need to loop through its children and connect the custom onTouched() and onTouchEnded() functions to each child BasePart.

The following code sample connects all BaseParts of a multi‑part model to collision events and tracks the total number of collisions with other parts.

Model Collision

local model = script.Parent
local numTouchingParts = 0
local function onTouched(otherPart)
-- Ignore instances of the model intersecting with itself
if otherPart:IsDescendantOf(model) then return end
-- Increase count of model parts touching
numTouchingParts += 1
print(model.Name, "intersected with ", otherPart.Name, "| Model parts touching:", numTouchingParts)
end
local function onTouchEnded(otherPart)
-- Ignore instances of the model un-intersecting with itself
if otherPart:IsDescendantOf(model) then return end
-- Decrease count of model parts touching
numTouchingParts -= 1
print(model.Name, "un-intersected from", otherPart.Name, "| Model parts touching:", numTouchingParts)
end
for _, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
child.Touched:Connect(onTouched)
child.TouchEnded:Connect(onTouchEnded)
end
end

Collision Fidelity

The CollisionFidelity property for a MeshPart, also available for PartOperation instances, determines how closely the part's physical hitbox matches its visual representation. In most cases, the Default setting is suitable, but other settings can be selected for best performance (Hull/Box) versus accuracy (PreciseConvexDecomposition).

Original mesh of castle tower

Collision Filtering

Collision filtering defines which physical parts collide with others. You can configure filtering for numerous objects through collision groups or you can control collisions on a part‑to‑part basis with NoCollisionConstraint instances.

Collision Groups

Collision groups let you assign BaseParts to dedicated groups and specify whether or not they collide with those in other groups. Parts within non‑colliding groups pass through each other completely, even if both parts have their CanCollide property set to true.

In the video above, the spinning objects are in different collision groups such that they collide with objects of another color but not with objects of their own color

You can easily set up collision groups through Studio's Collision Groups Editor, accessible by clicking the Collision Groups button in the Model tab.

Collision Groups tool indicated in Model tab of Studio

The editor functions in either List View which favors docking to the left or right side of Studio, or in a wider Table View, which favors docking to the top or bottom.

List View example in Collision Groups Editor

Creating Groups

The editor includes one Default collision group which cannot be renamed or deleted. All BaseParts automatically belong to this default group unless assigned to another group, meaning that they will collide with all other objects in the Default group.

To create a new collision group:

  1. Click the Add Group button along the top of the editor panel, enter a new group name, and press Enter. The new group appears in both columns of list view, or in both the left column and upper row of table view.

    New group added to Collision Groups Editor in List View
  2. Repeat the process if necessary, choosing a unique and descriptive name for each group. Note that you can change a group's name during development by clicking in its field, or by selecting it and clicking the rename button.

    Button and field indicated for renaming a group in the Collision Groups Editor

Assigning Objects to Groups

To assign objects to groups you've created through the Studio editor:

  1. Select one or more BaseParts that qualify as part of a collision group.

  2. Assign them to the group by clicking the button for its row. Objects can belong to only one collision group at a time, so placing them in a new group removes them from their current group.

    Plus button indicated in Collision Groups Editor for adding selected parts to a group

Once assigned, the new group is reflected under the object's CollisionGroup property.

Chosen collision group indicated as the part's CollisionGroup property

Configuring Group Collisions

Under default configuration, objects in all groups collide with each other. To prevent objects in one group from colliding with objects in another group, uncheck the box in the respective row/column.

In the following example, objects in the Cubes group will not collide with objects in the Doors group.

Group configured in List View of Collision Groups Editor

Part-to-Part Filtering

To prevent collisions between two specific parts without setting up collision groups, such as between a vehicle's wheel and its chassis, consider the No Collision constraint. Advantages include:

  • Collision groups and/or configuration scripts are not required, so you can easily create and share models with customized collision filtering.
  • Connected parts will not collide with each other, but they can still collide with other objects.

Disabling Character Collisions

Roblox player characters collide with each other by default. This can lead to interesting but unintended gameplay, such as characters jumping on top of each other to reach specific areas. If this behavior is undesirable, you can prevent it through the following Script in ServerScriptService.

Script - Disable Character Collisions

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
PhysicsService:RegisterCollisionGroup("Characters")
PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)
local function onDescendantAdded(descendant)
-- Set collision group for any part descendant
if descendant:IsA("BasePart") then
descendant.CollisionGroup = "Characters"
end
end
local function onCharacterAdded(character)
-- Process existing and new descendants for physics setup
for _, descendant in pairs(character:GetDescendants()) do
onDescendantAdded(descendant)
end
character.DescendantAdded:Connect(onDescendantAdded)
end
Players.PlayerAdded:Connect(function(player)
-- Detect when the player's character is added
player.CharacterAdded:Connect(onCharacterAdded)
end)