Passsing variables into IEnumerator?

Hello I am having some trouble with my IEnumerator function in which the variables I give the function do not seem to work. My script calls the IEnumerator function but nothing is ever executed in the function. I am assuming there is some special way of passing in variables but I have not found anything that has worked. Feel free to reference my script and thanks for the help.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class slowMovement : MonoBehaviour {

	public int damage;
	public float time;
	public float newSpeed;
	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {
	}

	void OnTriggerEnter (Collider col) {
	    if (col.GetComponent<Collider>().tag == "LocalPlayer") {
			Debug.Log ("hit the remoteplayer");
			var hit = col.gameObject;
			var health = hit.GetComponent<Health> ();
			var movement = hit.GetComponent<PlayerController> ();
			if (health != null) {
				health.TakeDamage (damage);
			}
			if (movement != null) {
				movement.speed = newSpeed;
				StartCoroutine (timeDelay (time, movement));
			}

			Destroy (gameObject);
		}  

	}

	IEnumerator timeDelay (float time, PlayerController move) {
		yield return new WaitForSeconds (time);
		move.speed = 5f;
	}
		
}

You’re destroying the GameObject as soon as you start the coroutine. That kills any coroutines running on it. So the coroutine gets started then immediately stops.

There are several ways you could handle this. One would be to have the “change speed after a delay” functionality on the object whose speed is being changed, rather than on the object that changes it. . Another would be to hold off destroying the “slowMovement” object until after it’s completed what it needs to do.