I've been wanting to make a zombie staff that summons a zombie that defends for you, I am trying to find Information but It just shows the opposite, I did manage to find one but I want It so that the NPC finds targets by Itself when being summoned
Problems with the script:
- The script follows everyone In the server currently
- The script (ServerScript) won't work when being cloned In ReplicaStorage
Script:
local NPC = script.Parent
local Pathfinding = game:GetService("PathfindingService")
local player
game.Players.PlayerAdded:Connect(function(client)
player = client
end)
repeat wait() until player ~= nil
while wait() do
local path = Pathfinding:CreatePath()
path:ComputeAsync(NPC.Torso.Position, player.Character.PrimaryPart.Position)
if path.Status == Enum.PathStatus.Success then
local Positions = path:GetWaypoints()
for i,v in pairs(Positions) do
local position = Instance.new("Part")
position.Parent = game.Workspace
position.Size = Vector3.new(1,1,1)
position.Position = v.Position
position.Transparency = 1
NPC.Humanoid:MoveTo(position.Position)
NPC.Humanoid.MoveToFinished:Wait(2)
position:Destroy()
end
end
end

4 comments
Alright thanks! Just a question, where should I place the script?
in the zombie
I mean't the script Inside of the pathfinding
?