local finish
local character = workspace:WaitForChild("Monster")
local humanoid = character.Humanoid
local service = game:GetService("PathfindingService")
local temp
local path
local points
if finish ~= nil then
path = service:FindPathAsync(character.Torso.Position,finish)
points = path:GetWaypoints()
temp = true
else
wait()
end
function gethumanoids()
local humanoidpos = {}
for i,v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") ~= script.Parent then
table.insert(humanoidpos,(humanoid - v.HumanoidRootPart.Position.Magnitude ))
end
end
table.sort(humanoidpos)
for i,v in pairs(humanoidpos) do
if v ~= 1 then
table.remove(humanoidpos.i)
end
end
for i,v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") and v ~= script.Parent then
if (script.Parent.HumanoidRootPart.Position - v.HumanoidRootPart.Position.Magnitude) == humanoidpos[1] then
if humanoidpos[1] ~= nil then
finish = v.HumanoidRootPart.Position
end
end
end
end
end
if temp ~= false then
for i,v in pairs(points) do
wait(.2)
gethumanoids()
local part = Instance.new("Part", workspace)
part.Size = Vector3.new(1,0.5,1)
part.Anchored = true
part.Name = "Stud"
part.CanCollide = false
part.Position = v.Position
humanoid.WalkToPoint = part.Position
end
end
Workspace.Script:50: bad argument #1 (table expected, got nil)
The above error given from the output is in line 50, the points is nil for some reason even if i made 2 solutions to that. Any solutions?

4 comments
The following script is to make the "monster" target the nearest player.
where are you using points??? All I see is “local points”
Do view all 63 lines
You never set the value of local points though because you just do if finish ~= nil then else wait() end and then it continues on the script until the bottom and errors