local monster = script.Parent.Torso
local humanoid = script.Parent.Humanoid
function findTarget(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
local body = nil
local human = nil
local body2 = nil
for x = 1, #list do
body2 = list[x]
print(x)
print(body)
if (body2.className == "Model") and (body2 ~= script.Parent) then
body = body2:findFirstChild("HumanoidRootPart") or body2:findFirstChild("Torso")
human = body2:findFirstChild("Humanoid")
if (body ~= nil) and (human ~= nil) and (human.Health > 0) then
if (body.Position - pos).magnitude < dist then
torso = body
dist = (body.Position - pos).magnitude
end
end
end
end
print(body)
return torso
end
while true do
wait()
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local target = findTarget(script.Parent.Torso)
path:ComputeAsync(monster.position, target.position)
local waypoints = path:GetWaypoints()
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end
end
tells me Workspace.spook1.Script:19: bad argument #2 (Vector3 expected, got Object)
