Minimap isn't working

I am making a Minimap using an image I already have from my game, and I want it to show the exact position of the player in relation to the world. I have tried several ways, but it’s not working.

Now the imageLabel is ending up outside the frame.

Before:


After:

Code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")

local minimap = script.Parent
local mapImage = minimap:WaitForChild("MapImage")
local playerDot = minimap:WaitForChild("PlayerDot")

-- LIMITES REAIS DO MAPA
local MAP_MIN = Vector2.new(-17085.516, -11718.192)
local MAP_MAX = Vector2.new(13314.112, 18681.436)
local MAP_SIZE = MAP_MAX - MAP_MIN

local ZOOM = 1.6

mapImage.AnchorPoint = Vector2.new(0.5, 0.5)
mapImage.Position = UDim2.fromScale(0.5, 0.5)

game:GetService("RunService").RenderStepped:Connect(function()
	local pos = root.Position

	-- Eixo X correto
	local nx = (pos.X - MAP_MIN.X) / MAP_SIZE.X

	-- Eixo Z invertido (correção)
	local ny = 1 - ((pos.Z - MAP_MIN.Y) / MAP_SIZE.Y)

	mapImage.Position = UDim2.fromScale(
		0.5 - nx * ZOOM,
		0.5 - ny * ZOOM
	)
end)

4 Likes

Have you tried making the AnchorPoint (0, 0) yet? (sorry this reply is so uselessly short by the way, just want to see if changing it works.)

Assuming that the anchor point is properly set to 0.5, 0.5, I’m pretty sure the issue is in the way that the zoom is applied. The zoom shouldn’t be affecting the position, the zoom should be affecting the scale of the map.
First just try removing the ZOOM, then, if that fixes the particular issue, you can re-implement the zoom in the form of scaling the minimap