I am getting a random serialization error and don't know why. How do I fix this? What is it saying?

using UnityEngine;
using System.Collections;
public class spawn : MonoBehaviour {
//This initalises ‘Player Prefab’ to mean whatever asset you want in the actual editor as a intiger (int).
GameObject PlayerPrefab;
public int WaitTime = 10;
public int repeatrate = 0;
public int DeathTime = 20;
//‘voids’ are the fundamental in scripts. They’re a kind of function (which is what they’re called in Jarva Script)
//The start void will run the code on startup.
//The spawn will run according to the “InvokeRepeating”.
void Start()
{
//InvokeRepeating is what enables the ‘Spawn’ function to run according to the ‘spawnWaittime’
InvokeRepeating(“Spawn”, WaitTime, repeatrate);
}
void Spawn()
{
//The spawning code. The ‘Vector3’ line initialises the ‘position’ variable and makes the object
//Spawn with a certain y and x value but the z value is randomly inbetween two numbers (Random.Range)
Vector3 position = new Vector3 (3.75389f,-1.7257f,Random.Range(-5.0f,14.0f));
//Instantiate essentially means spawn. It has 3 input points: asset, location (x,y,z), Rotation
Instantiate(PlayerPrefab, position, Quaternion.identity);
//This destroys a an object or asset within a certain time frame e.g. Destroy(object, Time)
}
}
I’ve got a lot of comments explaining how the code works. It was working as it should and then it just broke randomly. I don’t know why. Here is the error. Its really long: Range is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour ‘spawn’ on game object ‘CustomerH’.
See “Script Serialization” page in the Unity Manual for further details.
UnityEngine.Random:Range(Single, Single)
spawn:.ctor() (at Assets/Scripts/spawn.cs:8)

I also understand that it says to refer to the unity manual but the stuff in the manual is confusing me too. I’m just having trouble deciphering this.

We need to see the full code from the start to at least the Start method because the error points to line 8, and there’s nothing wrong with line 8 in this code. In general btw, you should not use constructors in MonoBehaviours (except maybe static constructors) unless you like a headache. Use Awake, Start and OnEnabled instead. Also methods and calculations are not allowed in field initializers. You should try renaming the Spawn method to something else and check if it still gives an error. Don’t know how InvokeRepeating works on the inside, it may not be case sensitive and it may call the default constructor of your class. That’s all I can think of without seeing more of the code.

Nvm. The error re-appeared as quickly as it disappeared.