Help with spawning NPC, it doesnt move!

I’ve got this script which spawns an npc zombie in when you use a proximity prompt, however it spawns but it doesn’t move. The npc works as it in makes noises and attacks you but it just doesn’t move.
I have other npcs which spawn fine and move around normally. When i put the zombie npc model into the workspace it moves around fine and works as intended, its just when i spawn it with the script it doesn’t move.

Code:

local spawnLocation = game.Workspace.EarlyExitZombieSpawner.CFrame
local prompt = script.Parent

prompt.Triggered:Connect(function(player)
	local model = game:GetService("ServerStorage").EarlyExitZombie:Clone()
	model.Parent = game.Workspace

	local position = spawnLocation.Position + Vector3.yAxis* 5
	local cFrameNew = CFrame.new(position)
	model:PivotTo(cFrameNew)
end)

Video: https://gyazo.com/ef8ec748520323202581e86635ec51ad

2 Likes

are there any errors? this is probably likely because the script is not giving the instances/assets time to load.

Nah no errors, how would i give them time to load? I was thinking a wait(5) before it sets the position but that did nothing really

the best practice is to use WaitForChild(“”) but I don’t know what is happening as you said there is no error. and i have no access to the other scripts

Hmm i used WaitForChild on the model and it still doesn’t move

local model = game:GetService("ServerStorage"):WaitForChild("EarlyExitZombie"):Clone()

can I see the code for the npc?

Theres a few scripts in the npc, heres the move script which i think will be the best for you to look at

local CurrentPart = nil
local MaxInc = 60

function onTouched(hit)
	if hit.Parent == nil then
		return
	end

	local humanoid = hit.Parent:findFirstChild("Humanoid")

	if humanoid == nil then
		CurrentPart = hit
	end
end

function waitForChild(parent, childName)
	local child = parent:findFirstChild(childName)

	if child then
		return child
	end

	while true do
		print(childName)

		child = parent.ChildAdded:wait()

		if child.Name==childName then
			return child
		end
	end
end

local Figure = script.Parent
local Humanoid = waitForChild(Figure, "Humanoid")
local Torso = waitForChild(Figure, "HumanoidRootPart")
local Left = waitForChild(Figure, "LeftFoot")
local Right = waitForChild(Figure, "RightFoot")

Humanoid.Jump = true

Left.Touched:connect(onTouched)
Right.Touched:connect(onTouched)

while true do
	wait(math.random(2, 6))

	if CurrentPart ~= nil then
		if math.random(5, 7) == 1 then
			Humanoid.Jump = true
		end

		Humanoid:MoveTo(Torso.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)), CurrentPart)
	end
end

there doesn’t seem to be any problem with this script either, do you mind sharing the place file or just the spawner and NPC?

1 Like