Why not just:
IF object_id('YourFunctionName', 'FN') IS NOT NULL
BEGIN
DROP FUNCTION [dbo].[YourFunctionName]
END
GO
The second argument of object_id
is optional, but can help to identify the correct object. There are numerous possible values for this type argument, particularly: