Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to teleport player to a point they clicked on a minimap?

Asked by 2 years ago

I have rendered the entire map into a bird's-eye view image, and have it as an ImageButton. Here's my weak attempt at the question:

local Players = game:GetService('Players')
local localPlayer = Players.LocalPlayer
local UserInputService = game:GetService('UserInputService')
local button = localPlayer.PlayerGui:WaitForChild('Gui').Map

button .MouseButton1Click:Connect(function()
    local relativeMousePos = UserInputService:GetMouseLocation() - button.AbsolutePosition
    local pos = Vector3.new(relativeMousePos.X, 200, relativeMousePos.Y)
    print(pos)
    localPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(pos)
end)

While it certainly does teleport, but neither does the scale or the position aligns with the actual map.

I have seen these posts: DevForum: 2D positioning to 3D positioning, DevForum: How would I get the world position of a GUI properly?, DevForum: How to find the cursor position inside a gui object

However I cannot understand them well enough to combine and apply them to my situation.

Original post, with an answer which did not fit the question

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I don't really have a answer for the script, but I think I did manage to figure out what the devforums post means:

  1. Its about how If you click on the mini-map It makes a WayPoint, and (For me using PahtFinding) a WayPoint Is a part or location placed where NPCS or Players go to, A example Is this:
local NPC = script.Parent
local PathFinding = game:GetService("PathfindingService")
local Target = game.Workspace.Location

while wait() do
    local Path = PathFinding:CreatePath()
    Path:ComputeAsync(NPC.Torso.Position, Target.Position)
    if Path.Status == Enum.PathStatus.Success then
        local Waypoints = Path:GetWaypoints()
        for i,v in pairs(Waypoints) do
            local Part = Instance.new("Part", workspace)
            Part.CanCollide = false
            Part.Anchored = true
            Part.Transparency = 1
            Part.Position = v.Position
            NPC.Humanoid:MoveTo(Part.Position)
            NPC.Humanoid.MoveToFinished:Wait()
            Part:Destroy()
        end
    end
end
  1. The person Is making a GUI that Is placed In a specific spot In the mini-map which clicked created a part or location that either teleports the player there or A big arrow points down In the direction

  2. The person Is trying to make a movable GUI that has a shadow below the GUI, however It appears to not move to the correct position

Hope this helps!

Ad

Answer this question