Yield Statement Problems

I have this script Save() (Javascript) in which I send a message to a C# script to run the below function, which then sets the variable “receievedMessage” in Save() to “Success” or “Fail”. Both scripts work great, but as soon as I add the 6th line with the yield, it throws me the error: “ArgumentException: method return type is incompatible”. No idea why. I also tried putting the yield in it’s own function and calling it, but then it tells me that the parent object is inactive (which it really is active, and gameObject.activeSelf says it’s active), I don’t have any code that would deactivate it.

Does this have something to do with the SendMessage? That’s the only thing I can figure, but I don’t know any other way to do a wait function. And before someone says to do it all in C#, the entire project is in javascript, I only needed one script in C# to use Parse.

Thanks, I appreciate help!

The JavaScript Script:

public function Save(upload : boolean) {
	if (upload) {
    	while (receivedMessage == null)
    		yield WaitForSeconds(2);
    		Debug.Log("ReceivedMessage: " + receivedMessage);
    	if (receivedMessage == "Success")
 			GameObject.Find ("ResultText").GetComponent(UI.Text).text = "Upload Success!";
 		if (receivedMessage == "Failed")
    		GameObject.Find ("ResultText").GetComponent(UI.Text).text = "Upload Failed: Check Connection or Save Offline";

And the C# Script:

public class ParseHelperMethods : MonoBehaviour {
	public void UploadToParse() {
		string levelName = saveScript.levelName;
		string filePath = saveScript.filePath;
		var levelData = System.IO.File.ReadAllBytes(filePath + "/" + levelName + ".txt");
		var levelObject = new ParseObject("Levels");
		levelObject["author"] = ParseUser.CurrentUser;
		levelObject["levelName"] = levelName;
		levelObject["levelData"] = levelData;
		levelObject.SaveAsync().ContinueWith(task =>
			if (task.IsCanceled || task.IsFaulted)
				Debug.Log("FAILED TO UPLOAD");
				saveScript.receivedMessage = "Failed";
				saveScript.receivedMessage = "Success";

Not 100% sure what is happening, but I don’t think you need to use yield WaitForSeconds(2); there. You have a while (receivedMessage == null) loop which should just halt your code and wait for receivedMessage to get set. Try yield return 0; or maybe yield return null; instead and see if that helps. I don’t use Javascript, so I hope this is helpful.

I found that the problem came down to Parse. You can’t call yields or a lot of other functions within a Parse statement. Thanks all for the replies, I’ll mark turtleburgers’ response as the answer as I did end up not using the yield in my case (but I did have to in the C# script), which was part of the problem. Cheers!