Raycast Hit Detection

So I need help trying to figure out how to make a raycast hit detection.
I want to place a part at the position where the part was hit.

local part = workspace.Part

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {part}

so now the cast will ignore the part itself

local cast = workspace:Raycast(part.Position,part.CFrame.LookVector * (how far u want the cast to travel),raycastParams)

if cast then

1 Like

Yes, but that would just position it in the middle of the part.

then use vector3.new for the travel

Nothing happening:

	local raycastResult = workspace:Raycast(part.Position, part.CFrame.LookVector * Vector3.new(100,100,100), raycastParams)

	if raycastResult then

i just do this for my game

wait just change the travel to 20

Nothing still happens. I don’t think look vector would work.

u have to confirm which side is the part facing tho

I want to check it on all sides.

i dont think its possible though

if u want to really check every sides then u have to repeat the raycast on every sides

lets say u want to make the raycast cast backwards then its -part.CFrame.LookVector * 20 i think and then etc

Firstly, use local RaycastResult = workspace:Raycast(--[[Arguments here]]).
Finally, when the raycast result is present, use RaycastResult.Position. Enjoy.

@CipherFunctions is right, you can get the hit point by using RaycastResult.Position

Would be good if you read the documentation of Raycast, cause RaycastResult has a few properties that could help you, not only the Position or Instance, for example, .Normal, which is the angle face where the hit point occurs, if you want to align the new part you are placing in the hit point would be helpful



Yes but what would I put in the rayDireciton?

workspace:Raycast(rayOrigin, rayDirection???, rayParams)

Probably whatever you had here?