How to get a position in the world from a GUI position?

Hi, I’m making a system in my minimap where if you click anywhere on the map, a marker will be positioned at that point and a part in the workspace at that point, I’m close to finishing it, but it’s just my part doesn’t position the part correctly in the workspace. Here’s my code I’m using for it:

local GPS_BUTTON = script.Parent;

local player  = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()

local location = script.Parent.Parent:WaitForChild("Location")

local UserInputService = game:GetService("UserInputService")

local char = player.Character or player.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")

local locations = {};

    if hit.Name == "GPS" then
        for index, location in ipairs(locations) do
        locations = {}

    if game.Workspace:FindFirstChild("GPS") then return end
    local minX, minY = GPS_BUTTON.AbsolutePosition.X, GPS_BUTTON.AbsolutePosition.Y
    local maxX, maxY = minX + GPS_BUTTON.AbsoluteSize.X, minY + GPS_BUTTON.AbsoluteSize.Y
    local mouseX = math.clamp(UserInputService:GetMouseLocation().X, minX, maxX)
    local mouseY = math.clamp(UserInputService:GetMouseLocation().Y, minY, maxY)
    local xPixel, yPixel = (maxX - minX), (maxY - minY)
    local xPos = (mouseX - minX) / xPixel
    local yPos = (mouseY - minY) / xPixel
    local scale =, 0, yPos, 0)
    local newLo = location:Clone()
    table.insert(locations, newLo)
    newLo.Visible = true
    newLo.Position = scale
    newLo.Parent = location.Parent
    local anotherLo = newLo:Clone()
    anotherLo.Visible = true
    anotherLo.Size =, 0,0.111, 0)
    anotherLo.Position = scale
    anotherLo.Parent = GPS_BUTTON.Parent.Parent.Frame.Map
    table.insert(locations, anotherLo)
    local Raycast = game.Workspace.CurrentCamera:ScreenPointToRay(newLo.AbsolutePosition.X + (0.5), newLo.AbsolutePosition.Y + (0.5), 2)
    local Ray =, Raycast.Direction * 100)
    local hit, pos = game.Workspace:FindPartOnRay(Ray, nil)
    local PART ="Part")
    PART.Size = PART.Size +, 20, 0)
    PART.Position = pos
    PART.Anchored = true
    PART.Parent = game.Workspace
    PART.CanCollide = false

    PART.Transparency = 0.5
    PART.Name = "GPS";

and here are some images of how it works:

As you can see, the location marker in the map is somewhere else whereas the part in the workspace is close to that point.

Thanks for any help. :slight_smile:

Hello, well i’m not so much know scripting, but ur block : “GPS”. Not destoyed? (if i’m wrong , sorry.)

MouseButton1Down(x,y) gives you the coordinates of the klick on the minimap
then get the players characters position and add X,Y and set the waypoint