Collapse Sidebar


FindPartOnRay uses raycasting to find the first BasePart intersecting with a given DataType/Ray. This function returns the position of intersection, the surface normal of the intersecting BasePart at the point of intersection, and the BasePart's BasePart/Material.

local character = game.Players.LocalPlayer.Character
-- Get the head
local head = character:FindFirstChild("Head")
-- Build a ray in the direction the head is facing
local origin = head.Position
local lookDirection = head.CFrame.lookVector
local ray = Ray.new(origin, lookDirection * 500)
-- Raycast, ignoring the player's character
local part, hitPosition = workspace:FindPartOnRay(ray, character)
if part then
	print("Hit part: " .. part:GetFullName())
	print("Did not hit part")

The terrainCellsAreCubes and ignoreWater parameters determine whether Terrain cells should be treated as cubes or not, and whether water should be ignored or not.

If the ignoreDescendantsInstance parameter is provided, the raycasting calculation will ignore the given object and all of its descendants. It behaves similar to the Mouse/TargetFilter property.

In order to white-list or ignore multiple objects and their descendants, use these variants: WorldRoot/FindPartOnRayWithWhitelist|FindPartOnRayWithWhitelist and WorldRoot/FindPartOnRayWithIgnoreList|FindPartOnRayWithIgnoreList.


  • Theoretically, a ray extends infinitely in one direction. However, the max length of the direction vector on Roblox is 5000 studs
  • The length of the direction vector is important - parts further away than its length will not be tested
  • If the ray does not intersect a part, the return values will be nil and the point at the end of the ray, respectively
  • Parts that are in a PhysicsService/SetPartCollisionGroup|collision group that does not collide with the “Default” collision group are ignored implicitly

For more information on how raycasting works in Roblox, please see the articles on raycasting basics and how to make raycasting guns.


Name Type Default Description




Return Type Summary

The BasePart (or Terrain) hit, the DataType/Vector3 point of intersection, the DataType/Vector3 surface normal at the point of intersection and the Enum/Material of the BasePart or terrain cell hit.