I got a question. When i start my script. This code always wrong by attempt to index field '?' (a nil value)! i'm wanna to know why? Codes(The wrong place):
function findClosestComputer(Character)
for i = 1,#AllComputers do
local Computer
local Distance = Player:DistanceFromCharacter(AllComputers[i].PrimaryPart.Position)
local NextDistance = Player:DistanceFromCharacter(AllComputers[i+1].PrimaryPart.Position)
--He said Here! attempt to index field '?' (a nil value)
if Distance < NextDistance then
Computer = AllComputers[i]
print("1")
else
Computer = AllComputers[i+1]
print("2")
end
end
end
Thank you!

1 comment
You're trying to index the PrimaryPart of a nil value of the table. It's happening because of the [i+1] part. Make sure you're not trying to index more than the contents of the table.