Using AppleScript, how to confirm a folder action is actually removed?

I'm writing AppleScript to make a new folder action and attach it to a specified folder. In case there's already a folder action attached to the folder before make new folder action is executed, I want to delete that folder action already exists.

tell application "System Events"
	repeat with i from 1 to count of folder actions
		if (path of folder action i) as string is equal to "/Users/foo/MyFolder" then
			delete folder action i
			exit repeat
		end if
	end repeat
  make new folder action at end of folder actions with properties {name:"MyFolderAction", path:"/Users/foo/MyFolder"}
end tell

However, it is still often that when make new folder action is executed, an error occured saying that "There is already a folder action with this path: /Users/foo/MyFolder".

Maybe it's because that when make new folder action is executed, the delete folder action has not completed yet. Adding a delay 1 before make new folder action makes the error occured less fruequently, but not disappeared.

Is there any method to confirm that the folder action is really deleted before make new folder action is executed?