That isn't your whole function - if nothing else it doesn't give a value to the variable so the RETURN is a little pointless! :laugh:
Without the whole function it's difficult to be sure (and since we don't have your types, we can't test your code exactly) but the most common reason for this is that your function contains one or more GO commands. These "break" the code and anything declared above the GO is not available below:
DECLARE @X INT
SET @X = 3
SELECT @X
GO
SELECT @X
Will give the error message you describe.