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)
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
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