Prefab instatiate

Hi, I have a script to create a bullet, and it works fine, but I keep getting an error "The prefab you want to instantiate is null."

Here is the script:

var prefab : Transform;

function Update () {
if(Input.GetButtonDown("Fire1"))
{

Instantiate(prefab, transform.position,transform.rotation);

}

}

I have set the prefab variable to the bullet in the Inspector tab, but I still keep getting that error. Why?

If you changed the variable type from something else to Transform at any point, it'll still look like you have a prefab added but it'll not work correctly when you try instantiate. Try remove the reference to the prefab, then add it back in

change “var prefab : Transform;” to “var prefab : GameObject;” and then drag the prefab to the script.
that should work.