Raycast to detect wall does not detect the own wall it was sent from

I am making a string trap setup script, and when you are selecting where the start of the string goes, the string should not go through a wall. This works, except for the own wall that the string is placed on. Here is a video showing the issue:


And this is the code for the raycast:

local raycastResult = workspace:Raycast(stringPosition, (mousePos - stringPosition).Unit * ((mousePos - stringPosition).Magnitude * 0.9999)

I assume this is because the origin of the raycast is placed inside of the part, which means it cannot hit the face of the part. Is there any way around this?
Any help is appreciated.

You have the direction of the vector right? Just move the starting vector backward based on that direction so it can immediately hit the surface it spawned on

local dir = (mousePos - stringPosition).Unit
local raycastResult = workspace:Raycast(stringPosition - dir * .1, dir * ((mousePos - stringPosition).Magnitude * 0.9999)
1 Like