Raycast not detecting part

  • What are you attempting to achieve? (Keep it simple and clear)

I’m making a custom pathfinding module. Im currently making the grid part.

  • What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)

My issue is that when im raycasting it does not detect the baseplate when im checking if the ray hits anything.

Here im checking if the ray hits anything

And here im not checking if the ray hits anything

Here is my module code. Im making the parts in another script

  • What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
    I’ve checked the wiki and unsuccesfully found a answer to my problem

It seems to me that your Grid Height is just short enough that the ray is not able to reach the baseplate. If a ray doesn’t hit anything, then hitpos will be the origin of the ray plus the direction (including the length of the direction)
If I’m correct, that’s why the red dots appear to hit the baseplate correctly, when in reality they don’t quite make it

(mad script font, by the way)


If you ever have problems with raycasting, I always find that visualising the Ray helps a lot.

You can do this with the following code:

local PartRay = Instance.new(“Part”)
local Distance = Vector3.new(StartPosition, Position).magnitude
PartRay.Size = Vector3.new(1,1,Distance)
PartRay.CFrame = CFrame.new(StartPosition,Position) * CFrame.new(0,0,-StartPosition/2)

This will draw a part along the ray from the start to the end. You can then use that to determine what the Ray is hitting and why you’re not getting the results you wanted.