Gun Projectile Shooting In Wrong Direction (Javascript)

I created a gun script that will fire a projectile from a certain spawn point. The problem is, whenever it spawns, it instantiates going forward. If the spawn rotates (Lets say left) The bullet still shoots forward, not to the left. Help? Here’s is the part of the code that instantiates a bullet prefab:

var clone = Instantiate(projectile, spawn.transform.position, spawn.transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0,0,speed))

It looks like you have it always going in the z direction maybe try:

rigidbody.velocity = transform.forward * 10;


Or you could try

// Move the object forward along its z axis 1 unit/second.
transform.Translate(Vector3.forward * Time.deltaTime);
// Move the object upward in world space 1 unit/second.
transform.Translate(Vector3.up * Time.deltaTime, Space.World);

(This is the one i use for bullets)