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
Edited 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

Answer this question