Я пытался переместить NPC в путевую точку по порядку, это немного сработало, но затем оно начинает двигаться не по порядку и начинает вести себя странно.
Сценарий переноса:
for i,node in pairs(script.Parent.Parent.Parent.Cartnodes:GetChildren()) do
if node:IsA("BasePart") then
print(node.Name)
script.Parent.Parent:WaitForChild("Rafthuman"):MoveTo(node.Position)
script.Parent.Parent:WaitForChild("Rafthuman").MoveToFinished:Wait()
node:Destroy()
end
end





Неинтуитивно, порядок детей не определяется алфавитным порядком. Если вы посмотрите документы для Экземпляр: ПолучитьGhildren(), вы увидите это примечание:
The children are sorted by the order in which their Parent property was set to the object.
Поэтому, чтобы получить их в правильном порядке, вам нужно отсортировать список, прежде чем повторять его.
local raftHuman = script.Parent.Parent:WaitForChild("Rafthuman")
local nodes = script.Parent.Parent.Parent.Cartnodes
local children = nodes:GetChildren()
local sortedChildren = table.sort(children, function(a, b)
return a.Name < b.Name
end)
for i,node in ipairs(sortedChildren) do
if node:IsA("BasePart") then
print(node.Name)
raftHuman:MoveTo(node.Position)
raftHuman.MoveToFinished:Wait()
node:Destroy()
end
end