[SalesForce] Expected comma not found AMPScript error

I have the following code:

<script runat="server" language="Ampscript">
%%[ 
var @Country, @Preheader, @SubjectLine, @Text1, @Text2, @langRowsCount, @LanguageLookup

SET @Country = PersonMailingCountryCode
SET @LanguageLookup = LookupRows('Translation Table - Email 2', 'Country', @Country)
SET @langRowsCount = RowCount(@LanguageLookup)

IF @langRowsCount>1 THEN
SET @langRow = Row(@LanguageLookup, 1)
SET @SubjectLine = Field(@langRow, "SubjectLine")
SET @Preheader = Field(@langRow, "PreHeader")
SET @Text1 = Field(@langRow, "Text1")
SET @Text2 = Field(@langRow, "Text2")
ELSE 
SET @SubjectLine = 'X'
SET @Preheader = 'X'
SET @Text1 = 'X'
SET @Text1 = 'X'

ENDIF
]
</script>
<h3 style="font-family : arial,helvetica,sans-serif; font-size : 20px; color : #808080; line-height : 1; font-weight : bold; font-style : normal; ">%%=v(@Text1)=%%</h3>
%%=v(@Text2)=%%

When I try to preview it, I get the following errors:

An error occurred when attempting to parse TextEmailBody content for
Text content. MemberID: 6419050 JobID: 0 ListID: 0 Content Begins
With: To view this email as a web page, go to the link below, or copy
and paste it into your browser's add

An expected comma is not found in the varible declaration. Script:
var @Country, @Preheader, @SubjectLine, @Text1, @Text2SET @Country =
PersonMailingCountryCodeSET @LanguageLookup = ListID: 0 Index: 847

I can't seem to debug this on my own and will appreciate help with this

Best Answer

you are opening it twice.

<script runat="server" language="Ampscript> is the same as %%[ See tag based syntax.

You should write your script like this:

<script runat="server" language="Ampscript"> 
var @Country, @Preheader, @SubjectLine, @Text1, @Text2, @langRowsCount, @LanguageLookup

SET @Country = PersonMailingCountryCode
SET @LanguageLookup = LookupRows('Translation Table - Email 2', 'Country', @Country)
SET @langRowsCount = RowCount(@LanguageLookup)

IF @langRowsCount>1 THEN
SET @langRow = Row(@LanguageLookup, 1)
SET @SubjectLine = Field(@langRow, "SubjectLine")
SET @Preheader = Field(@langRow, "PreHeader")
SET @Text1 = Field(@langRow, "Text1")
SET @Text2 = Field(@langRow, "Text2")
ELSE 
SET @SubjectLine = 'X'
SET @Preheader = 'X'
SET @Text1 = 'X'
SET @Text1 = 'X'

ENDIF

</script>
<h3 style="font-family : arial,helvetica,sans-serif; font-size : 20px; color : #808080; line-height : 1; font-weight : bold; font-style : normal; ">%%=v(@Text1)=%%</h3>
%%=v(@Text2)=%%
Related Topic