I've tried to do it with Instance.new but it didn't work
local NPC = Instance.new("CreateMeshRig", game.Workspace)
I'd recommend you NOT to use animation rigs. I'm not sure why you'd want to use those, but it's probably best if you didn't. Make your own or get and customize a free model one. In addition, you cannot instantiate the rig, as it is not an instance. I'm pretty sure you can create your own NPC with mesh parts in it? Not entirely sure.
Instead of trying to create the rig from scratch using the script, it would be preferable that you have your rig already created, and stored in the the game's ServerStorage. This way you can use your script to clone the NPC out of the storage and into the Workspace with ease.
local NPC = game:GetService('ServerStorage'):WaitForChild('NPC') game.Players.PlayerAdded:connect(function(Player) NPC:Clone().Parent = workspace end)