Spawning an NPC after the other one is destroyed [NOT SOLVED]

I have two npcs that walk to certain points:


this is what it looks like when i run the test:
robloxapp-20221016-1127387.wmv (169.4 KB)

sorry for the horrible lag im on a bad computer

When the npcs stop they get :Destroy() 'ed after 1 second.
Now I want to spawn two more npcs in the same spot (where they started), and make them exactly like the old ones. Then loop it so it goes on forever.

I accidentally posted the other post in the Creations Feedback category. This is the new fixed post

look. you can add a boolValue to the npc and call it like “HasExploded”

and when the function that triggers the npc to get destroyed, this value gets set to true

and you can add like a loop for cheking that. if that value is true then
spawn another two npcs

you got what i mean?

1 Like

I’m pretty sure the value would also get deleted when the npc gets destroyed

could clone the NPC to sever storage, create a function spawnnpc and call the function whenever you’re destroying it

1 Like

Thanks, this could work. I will try. When would I clone the npc?

that is a lot simpler solution than mine

before it gits destroyed
make a clone of it and put it in replicated storage

then make a functions that moves that clone to the workspace
and put it in the spawnnpc function

not sure what your scripts are setup like, but in your script set the npc to a variable and clone it using the :Clone() function for models, and do your manipulations or whatever to the clone.

Alright, @Youssef_x9 and @2016Richman this is working so far
It clones the npc into serverstorage, to test if it still works i pulled it out of serverstorage and put it in workspace during the test. it works so far.

hope we helped you

1 Like

I will reply when i have more information

1 Like

Ok, when the npc starts walking it does this

local event = game.ReplicatedStorage.spawnNpc

local newClone = script.Parent.Parent:Clone()
newClone.Parent = game.ServerStorage

But, the code errors and this happens
“Argument 1 missing or nil”

I also have a localscript in ReplicatedFirst
that does this:

local event = game.ReplicatedStorage.spawnNpc
local function spawnNPC()

how do i fix this?

also, if you want the full script i can give you it

how about you put the clone in replicated storage instead

You setup your events wrong, you should have a script in ServerScriptService that holds the functions, because it’s going from client to server. You’d have a localscript that fires your event, and then the script in SSS replies by firing the function on the server side.

1 Like

All you have to do, is at the beginning of the script, store the npc’s clone
Then after the 1 second delay at the end, just before you destroy the npc
paste the clone into workspace
then destroy the npc

1 Like

Thanks, but I came up with a new idea to just make a separate script then every random number it spawns a new npc

Where would the local script be in and what would it look like? Im new to this firing event stuff

ok so i have this, i dont need the functions anymore

the script does this before the npc starts walking

local clone = script.Parent.Parent:Clone()
clone.Parent = game.ServerStorage
clone.Name = "newClone"

then after the npc is done walking it does this:


clone.Parent = game.Workspace.NPCs


it does spawn the npc, it changes the new npcs look, but it says this:

this is the line it errored:

local middle = game.Workspace.Spawn1Middle

also it does work for the first npc but not for the second.
now the new npc doesnt walk at all

What is Spawn1Middle, and is it actually in the workspace?