Help with player position on a moving mini map

So my script mostly works but it’s inaccurate on different screen resolutions on my 1920/1080 monitor it looks ok as long as you don’t move the viewport camera on the x axis i tried everything and nothing worked

----Player Indicator
task.spawn(function()
	while true do wait(RefreshRate)
		if MapsApp.Visible == true then
			if IsMiniMapLoaded == true then
				local CameraZoom = Cam.CFrame.Y

				--Player rotation
				local Character = plr.Character
				local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
				local CharacterRotation = HumanoidRootPart.Orientation.Y
				PlrIndicator.Rotation = -CharacterRotation - 90
				
				--indicator size
				local IndicatorSize = (CameraZoom / MapHight) / 1000
				PlrIndicator.Size = UDim2.fromScale(0.146 - IndicatorSize,0.069 - IndicatorSize)

				if AutoFocusOnPlayer == true then
					Cam.CFrame = Cam.CFrame + Vector3.new(HumanoidRootPart.Position.X - Cam.CFrame.X,0,HumanoidRootPart.Position.Z - Cam.CFrame.Z)
				else
					--Player position
					local CharacterPosition = HumanoidRootPart.Position
					local PositionOnCamera = Cam:WorldToViewportPoint(CharacterPosition)
					
					if PlrIndicator then
						local viewSize = VPF.AbsoluteSize

						local scaleX = PositionOnCamera.X 
						local scaleY = PositionOnCamera.Y

						PlrIndicator.Position = UDim2.new(scaleX - PlrIndicator.Size.X.Scale / 2, 0, scaleY - PlrIndicator.Size.Y.Scale / 2, 0)
						
						--Screen bounds
						local framePosition = VPF.AbsolutePosition -- Top-left corner of the frame
						local frameSize = VPF.AbsoluteSize -- Size of the frame in pixels

						-- Set boundaries using offset values relative to the frame size
						local MaxRight = framePosition.X + frameSize.X 
						local MaxLeft = framePosition.X 
						local MaxBottom = framePosition.Y + frameSize.Y 
						local MaxTop = framePosition.Y

						-- Get the absolute position of the player indicator (top-left corner)
						local PlrIndicatorPosX = PlrIndicator.AbsolutePosition.X
						local PlrIndicatorPosY = PlrIndicator.AbsolutePosition.Y

						-- Check if the player indicator is within the frame's bounds
						if PlrIndicatorPosX >= MaxLeft and PlrIndicatorPosX + PlrIndicator.AbsoluteSize.X <= MaxRight and 
							PlrIndicatorPosY >= MaxTop and PlrIndicatorPosY + PlrIndicator.AbsoluteSize.Y <= MaxBottom then
							PlrIndicator.Visible = true
						else
							PlrIndicator.Visible = false
						end
					end

				end



			else
				--load map
				MakeMiniMap()
			end
		else
			--de load map
			VPF:ClearAllChildren()
			IsMiniMapLoaded = false
		end

	end
end)

Making it relative to the viewport frame made it worse