Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to spawn an NPC *programatically*?

Asked by
Ribasu 127
6 years ago
Edited 6 years ago

I want to spawn an NPC using my code only. What are the requirements to do this? What attributes must I set?

So far, I have tried something like this:

local humanoid = Instance.new("Humanoid")

humanoid.RigType = "R15"

but seems that nothing spawns.

0
That just creates a new humanoid object, not an actual model of an NPC. T0XN 276 — 6y
0
You'll have to create each indicula part of the NPC, and position them correctly in the NPC. Then you'll have to insert each script that you wanted into the NPC (Animation, etc.) I think your best option is to put an already made NPC into server storage and just clone it from there and put it into workspace. zyrun 168 — 6y

1 answer

Log in to vote
0
Answered by
T0XN 276 Moderation Voter
6 years ago
Edited 6 years ago

The problem with your script is that you are only creating a new Humanoid object, not an actual model of an NPC. The script below uses an NPC model that is already made, then clones it into the workspace.

I'll assume that the properties that you want in the NPC are already set in the actual model.

local replicatedStorage = game:GetService('ReplicatedStorage')
local npc = replicatedStorage:WaitForChild('NPC')

local function cloneNPC()
    npc:Clone().Parent = workspace
end

cloneNPC() -- call this function whenever you want a new clone
0
I don't want one that is already made but to create this - how do I achieve this? Ribasu 127 — 6y
0
That would mean creating and setting all the properties necessary in an NPC. joints, decals, humanoid, torso, limbs, everything. Why would you want to do all this within the program? T0XN 276 — 6y
0
It's a lot of work, and if you wanted animations then that is a whole other aspect as well. T0XN 276 — 6y
0
OK thanks for your reply - perfectly answers what I want! Ribasu 127 — 6y
Ad

Answer this question