C# Extending Script causes InvalidCastException on Instantiate

This line works in the original script, but bugs(InvalidCastException) when run on the extended script.

Transform obj = (Transform) Instantiate(projectile,loc,transform.rotation);

Any ideas? Thanks in advance.

Instantiate returns an object of the same type of the prefab variable. You can change the prefab variable type to Transform:

Transform projectile; // drag the projectile prefab here
...
    Transform obj = Instantiate(projectile,loc,transform.rotation);

The prefab variable type may be equal to any component present in the prefab object, like Rigidbody, Collider, Transform, GameObject etc., thus using GameObject or Transform will work in any case, the only difference being the type returned by Instantiate.