local pathfindingService = game:GetService("PathfindingService") local player =…
- User
local pathfindingService = game:GetService("PathfindingService") local player = game.Players.LocalPlayer
local waypoint = nil -- текущая цель игрока local moving = false -- флаг, определяющий, движется ли игрок в данный момент
local function moveToWaypoint() if not waypoint then return end
local humanoidRootPart = player.Character and player.Character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local path = pathfindingService:CreatePath() path:ComputeAsync(humanoidRootPart.Position, waypoint.Position) if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do if waypoint.Action == Enum.PathWaypointAction.Jump then -- прыгаем на пути humanoidRootPart.Parent.Humanoid.Jump = true end humanoidRootPart.Parent.Humanoid:MoveTo(waypoint.Position) -- перемещаемся к каждой точке пути humanoidRootPart.Parent.Humanoid.MoveToFinished:Wait() -- ожидаем окончания перемещения к точке end -- добрались до последней точки пути waypoint = nil else -- не удалось найти путь, двигаемся к цели напрямую humanoidRootPart.Parent.Humanoid:MoveTo(waypoint.Position) while waypoint and humanoidRootPart.Parent.Humanoid.WalkSpeed ~= 0 do humanoidRootPart.Parent.Humanoid.MoveToFinished:Wait() -- ожидаем окончания перемещения if waypoint then humanoidRootPart.Parent.Humanoid:MoveTo(waypoint.Position) end end -- добрались до цели или была нажата кнопка "S" для прекращения движения waypoint = nil end moving = false -- закончили движениеend
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button2Down:Connect(function(hit) if not moving then waypoint = hit.Position
-- создаем коробку в целевой точке для поиска пути local part = Instance.new("Part") part.Position = Vector3.new(waypoint.X, waypoint.Y, waypoint.Z) part.Size = Vector3.new(1, 1, 1) part.Transparency = 1 part.CanCollide = false part.Anchored = true part.Parent = workspace waypoint = part moving = true moveToWaypoint() endend)
game:GetService("UserInputService").InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.S then -- прекращаем движение waypoint = nil end end) подкорректируй скрипт. Система дает сбой на строчке 59: attempt to index nil with 'Position'
- Assistant
Проблема возникает из-за попытки доступа к
waypoint.Position, когдаwaypointравенnil. Появление этой ошибки означает, что после выполнения условияwaypoint and humanoidRootPart.Parent.Humanoid.WalkSpeed ~= 0функцияmoveToWaypoint()вызывается снова без создания нового . Чтобы исправить эту проблему, вы можете добавить проверку наличия пути перед доступом к .