I asked this question before, but I don't think I explained it properly.
Anyways in the for loop I'm attempting to find all children in workspace called "StartAndEnd" and place their child called EndPoint in the table.
When I try to get a random value from this table I recieve the error:
Workspace.StartAndEnd.NPC.Pathfinding:18: attempt to index local 'TrueEnd' (a nil value)
Is this because I cant get the values from the table outside the for loop?
OwnEnd = script.Parent.Parent
EndPoints = {}
for i, Ends in pairs (workspace:GetChildren()) do
if Ends ~= OwnEnd and Ends.Name == "StartAndEnd" then
EndPoints[i] = Ends.EndPoint
end
end
wait(5)
local TrueEnd = EndPoints[math.random(1, 3)]
local Path = game:GetService("PathfindingService"):ComputeRawPathAsync(OwnEnd.StartPoint.Position, TrueEnd.Position, 500)

1 comment
My guess is that EndPoints[1], EndPoints[2] or EndPoints[3] is nil