NPC spawn problem

This code ran is to spawn an npc, make it move from one spot to another, and then disappear. Does anyone have an idea of how I could make multiple npcs spawn at different intervals whilst still having the same walking path?

local function pp()
	local randPos = math.random(1,2)

	local newModel = model:Clone()
	local newModelHumanoid = newModel.Humanoid
	newModel.Parent = game.Workspace
	if randPos == 1 then
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('1').CFrame.Position))
		for i, v in pairs(Folder1:GetChildren()) do
			newModelHumanoid:MoveTo(Folder1:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	else
		newModel:PivotTo(CFrame.new(Folder1:FindFirstChild('9').CFrame.Position))
		for i, v in pairs(Folder2:GetChildren()) do
			newModelHumanoid:MoveTo(Folder2:FindFirstChild(i).Position)
			newModelHumanoid.MoveToFinished:Wait()	
		end
	end

	newModel:Destroy()
end

while true do
	wait(1,10)
	pp()
end 
1 Like

You can use coroutines like this:

while true do
    coroutine.wrap(pp)()
    task.wait(1) -- the time between each npc
end
1 Like

Are you a bot? You post so quickly?

1 Like

Nah, am online on devforum most of the time.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.