How to reliably set waypoints by clicking on a Map GUI (ViewportFrame) in Roblox?

Hi everyone,

I’m trying to implement a feature where players can open a map GUI (using a ViewportFrame that shows a 3D view of the game world) and click anywhere on the map to set a waypoint in the actual game world.

The general idea is:

  • Display a scaled-down version of the map inside a ViewportFrame.
  • Detect where the player clicks on the map GUI.
  • Translate that click position into world coordinates.
  • Set a waypoint indicator in the game world that points towards the clicked location.

I’ve tried raycasting from the ViewportFrame camera and also from the main workspace camera, but my raycasts don’t reliably detect hits on the map parts, or they return nil even when clicking on visible parts.

My questions are:

  • What’s the best practice to convert clicks inside a ViewportFrame into real-world positions for waypoint placement?
  • Should I raycast against the cloned map inside the ViewportFrame or the actual workspace map?
  • Are there common pitfalls with raycasting and ViewportFrame cameras I should be aware of?
  • Any tips for making waypoints work smoothly and accurately from a map GUI?

Any sample code, tutorials, or advice would be much appreciated!

Thanks in advance!

Assuming your map is top-down, you should raycast them first, take the position relative to the part, and scale it up based on the difference to get the resulting position. However, you need to retrieve the mouse position relative to the viewport origin, which is likely your issue.

The ViewportFrame raycast is probably better. You can’t really translate before raycasting anyways.

The distance has a limit (of 1000 last time I checked).

I’ve never done it before.