Adding script to a new object at runtime

Whenever I run this code:

var entity = new pc.Entity();
            entity.name = "Shot";
            entity.addComponent("script",{}
           );
            entity.script.create("run", {});

I get the error: “entity.script.create is not a function”
I want to dynamically create an object and attach a script to it

Hm weird I just copy pasted your code into a test project and it worked. Can you share a link to your project?

So I had found another way, but I am currently using legacy scripts on a brand new project and it keeps saying “this.entity.script.create is not a function”