Part.Touched or spatial queries

What is the difference between using spatial queries and part Touched events?

Spatial Queries

Another place to learn more about the CanQuery property is in its announcement topic.


Touched event

  • Is only fired when two parts interact through physics simulations.
    • This means that manually adjusting the CFrame of a part or Tweening a part won’t activate the Touched event upon coming into contact with another part.

(For this example, let’s assume we have two parts: Part A and Part B )

  • If Part A is touched by Part B, BasePart.CanTouch has to be true for Part B or else the Touched event won’t be fired on Part A.

To be honest, I forgot that Raycasts were considered spatial queries. I mostly associated those with the OverlapParams from this announcement thread since that was the first time I’d really heard the term.

The original list I included of the spatial query operations was based on the CanQuery documentation page which didn’t include raycasting but I’ll be sure to add it to this post!

2 Likes

Spatial queries basically checks for parts within a 3D space, while a Touched event is a connection that fires when a physics collision happens.
Spatial queries include Raycast, and OverlapParams. This means that spatial queries runs once you call them and immedietely returns values. Example is, checking if a player is inside a safe zone after a time period.
Touched event fires everytime a part collides with “this” part, meaning it can multiply times (unless disconnected). Examples for this is checking if a player enters a part. We won’t know when they will enter, but we can set up a function if they did enter.

@StrongBigeMan9 Did you intentionally not include raycasts? Raycast is also a spatial query.

1 Like