Minimap Icons in the wrong position

Watch the video for what I’m saying to make sense

As you can see, if you get far away from the part which has the text label on it the text label goes into a completely wrong position, if you are close however it works. I have no idea why it does this

local Minimap = script.Parent:WaitForChild("Minimap")
local Arrow = Minimap:WaitForChild("Arrow")

local IconsFolder = game.Workspace:WaitForChild("Icons")

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

local Camera = Instance.new("Camera")
Camera.FieldOfView = 1
Camera.CameraType = Enum.CameraType.Scriptable
Camera.Parent = game.Workspace
Minimap.CurrentCamera = Camera

task.wait(2)

local function isPartFromCharacter(part)
	return part:IsDescendantOf(Character)
end

for i, Object in pairs(game.Workspace:GetDescendants()) do
	if isPartFromCharacter(Object) then
		continue 
	end
	if Object:IsA("Terrain") or not Object:IsA("BasePart") then
		continue 
	end
	Object:Clone().Parent = Minimap
end

for i, child in pairs(IconsFolder:GetChildren()) do
	local ViewportSize = Camera.ViewportSize
	local W2VP = Camera:WorldToViewportPoint(child.Position)
	local normalizedX = W2VP.X / ViewportSize.X
	local normalizedY = W2VP.Y / ViewportSize.Y

	local iconGui = game.Players.LocalPlayer.PlayerGui.MinimapGui.Minimap:FindFirstChild(child.Name.."GUI")
	if iconGui then
		iconGui.Position = UDim2.new(normalizedX, 0, normalizedY, 0)
	else
		local TextClone = script.Parent.Parent.TextLabel:Clone()
		TextClone.Text = child.Name
		TextClone.Name = child.Name.."GUI"
		TextClone.Position = UDim2.new(normalizedX, 0, normalizedY, 0)
		TextClone.Parent = game.Players.LocalPlayer.PlayerGui.MinimapGui.Minimap
		TextClone.BackgroundTransparency = 1
	end
end

function add()
	local ViewportSize = Camera.ViewportSize
	for i, child in pairs(IconsFolder:GetChildren()) do
		local W2VP = Camera:WorldToViewportPoint(child.Position)
		local normalizedX = W2VP.X / ViewportSize.X
		local normalizedY = W2VP.Y / ViewportSize.Y
		
		local iconGui = game.Players.LocalPlayer.PlayerGui.MinimapGui.Minimap:FindFirstChild(child.Name.."GUI")
		if iconGui then
			print("found")
			iconGui.Position = UDim2.new(normalizedX, 0, normalizedY, 0)
		else
			print("Not found")
		end
	end
end


function update()
	local camCFrame = CFrame.new(HumanoidRootPart.Position + Vector3.new(0, 10000, 0), HumanoidRootPart.Position)
	Camera.CFrame = camCFrame
	Arrow.Rotation = -HumanoidRootPart.Orientation.Y - 90
	add()
end

game["Run Service"]:BindToRenderStep("update", 1, update)

I should also add, if the X and Y size of the minimap are the same it works fine, this bug only occurs it the sized are NOT the same

You can try something like this, but I don’t know for sure if it will work.

local xRatio = ViewportSize.Y / ViewportSize.X
local normalizedX = (((W2VP.X - 0.5) * xRatio) + 0.5) / ViewportSize.X

The camera probably sees the viewport as a square, so what this should do is “fix” the X position based on the Y to X ratio.

tried it, same bug occurs. Thanks for the reply anyways