I currently got these lines of code set:

	if HRP.CFrame.LookVector:Dot(HRP.Velocity) > 0 then
		local RaycastResult = workspace:Raycast(HRP.Position, HRP.CFrame.LookVector*50)
		if not RaycastResult then forwards = true end
	elseif HRP.CFrame.LookVector:Dot(HRP.Velocity) < 0 then
			local RaycastResult = workspace:Raycast(HRP.Position, HRP.CFrame.LookVector*-50)
		if not RaycastResult then backwards = true end
	end

All this does is detect if the ray intersects and counts that as a hit, however I wanna make it so it only detects the part where the ray ends. I honestly don't even know if this is possible since I've looked everywhere and haven't found a thing.

And please don't mind my rep, I was pretty immature 4 years ago.