How do I find the CFrame of the PART OF the object a raycast touched?

Let’s say I make a raycast from a player to a wall. How do I find the CFrame RIGHT to the part where the wall got touched?

A Raycast returns a RaycastResult object when hitting BasePart or Terrain

Based on the information given by the RaycastResult, you can get the Instance and check if it’s a BasePart, if yes, get the CFrame Property.

Sources:

Raycasting | Documentation - Roblox Creator Hub

I’m not trying to get the CFrame of the instance. Let’s say the raycast touched the side. How do I get the CFrame of the side?

The RaycastResult object returns a property so called Normal, which gives the Vector3 of the normal vector of the intersected face.

You can use following code to determine which side of the wall has been hit:

local normal = result.Normal
local side = ""

if normal == Vector3.new(0, 1, 0) then
      side = "Top"
elseif normal == Vector3.new(0, -1, 0) then
      side = "Bottom"
elseif normal == Vector3.new(1, 0, 0) then
      side = "Right"
elseif normal == Vector3.new(-1, 0, 0) then
      side = "Left"
elseif normal == Vector3.new(0, 0, 1) then
      side = "Front"
elseif normal == Vector3.new(0, 0, -1) then
      side = "Back"
end

position = rayOrigin + RaycastResult.Distance * RayDirection
rotation = RaycastResult.Normal

EDIT: rotation is a bit more complicated depending on what you want

Okay, I’m going to show a drawing of what I mean

Ah understood, the following code should work if I am not mistaken.

local surfacePosition = raycastResult.Position
local normal = raycastResult.Normal
local wallCFrame = CFrame.new(surfacePosition, surfacePosition + normal)

Never mind I found it. I just used this.

local result = workspace:Raycast(origin, position)

if result then
     local ExactPoint = result.Position
end

Although, I did need that for something for another time. So thanks! And sorry for wasting time.