Townsend's side conceded four second-half tries at Murrayfield as the visitors threatened to cause an upset in Scotland's first autumn Test.
Scotland face world champions New Zealand in Edinburgh next weekend.
"We have got to make sure we don't give up possession in our half as cheaply and defend much better," he said.
"Credit to Samoa, they played really good rugby. The first 15 minutes, they kept a lot of ball, they attacked either through the forwards or out wide, and when we gave them opportunities off our restart or errors within our half, they made the most of them.
"They took their chances and their forwards were strong carriers.
"We know how great a side [the All Blacks] are in attack and defence, so this first game is history now, we can move on to things we need to be better at next week to play at our best against the All Blacks."
Stuart Hogg, Huw Jones and Stuart McInally scored first half tries and the Edinburgh hooker gave the Scots a 32-10 lead seven minutes after half-time, and although Alex Dunbar and Peter Horne also crossed for the hosts, scores from Piula Faasalele, Tim Nanai-Williams, Kieron Fonotia and Ofisa Treviranus kept Samoa firmly in the contest.
Scotland's failure to secure and control possession from the visitors' restarts led to two of those four concessions, and Townsend says he will examine how the side sets up for kick-offs in training.
"[The restart] is an aspect of the game, it's the third set-piece, so you've got to make sure you practice it," he told BBC Scotland.
"Today it cost us, but another day it might be line-out or scrums. It's always something you look at.
"We'll have a look at our set-up and what we could do differently and make sure the players practice their roles of communication in getting up for the ball in the air."