local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local…
- User
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local PathfindingService = game:GetService("PathfindingService") local Path
local function ClearPath() if Path then Path:Cancel() Path = nil end end
local function StopMovement() ClearPath() Player.Character.Humanoid:MoveTo(Player.Character.HumanoidRootPart.Position) end
Mouse.Button2Down:Connect(function() local TargetPosition = Mouse.Hit.p
ClearPath() local CanPathfind = pcall(function() Path = PathfindingService:CreatePath({ AgentRadius = 2, AgentHeight = 5, AgentCanJump = true, AgentMaxSlope = 45, MaxSmoothDistance = 0.5, MinLineWidth = 0.25, MaxStepHeight = 0.5, }) Path:ComputeAsync(Player.Character.HumanoidRootPart.Position, TargetPosition) end) if CanPathfind then while Path.Status ~= Enum.PathStatus.Success do Player.Character.Humanoid:MoveTo(Path:GetClosestPosition(Player.Character.HumanoidRootPart.Position)) Path:ComputeAsync(Player.Character.HumanoidRootPart.Position, TargetPosition) Path:Wait() end for _, Waypoint in ipairs(Path:GetWaypoints()) do Player.Character.Humanoid:MoveTo(Waypoint.Position) Waypoint.Action = Enum.PathWaypointAction.Jump Path:WaitForWaypoint(Waypoint) end ClearPath() else Player.Character.Humanoid:MoveTo(TargetPosition) endend)
Mouse.Button2Up:Connect(function() ClearPath() end)
game:GetService("UserInputService"):BindAction("StopMovement", StopMovement, false, Enum.KeyCode.S) Роблокс выдает мне следующую ошибку (Cancel is not a valid member of Path "Instance") Подкорректируй скрипт.
- Assistant
Ошибка возникает из-за того, что функция
Cancelбольше не существует вPathдля остановки пути. Вместо этого вы можете использовать методStopу Path, чтобы прервать вычисление пути. Вот исправленный код:local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local PathfindingService = game:GetService("PathfindingService") local Path local function ClearPath() if Path then Path:Stop() Path = nil end end local function StopMovement() ClearPath() Player.Character.Humanoid:MoveTo(Player.Character.HumanoidRootPart.Position) end Mouse.Button2Down:Connect(function() local TargetPosition = Mouse.Hit.p ClearPath() local CanPathfind = pcall(function() Path = PathfindingService:CreatePath({ AgentRadius = 2, AgentHeight = 5, AgentCanJump = true, AgentMaxSlope = 45, MaxSmoothDistance = 0.5, MinLineWidth = 0.25, MaxStepHeight = 0.5, }) Path:ComputeAsync(Player.Character.HumanoidRootPart.Position, TargetPosition) end) if CanPathfind then while Path.Status ~= Enum.PathStatus.Success do Player.Character.Humanoid:MoveTo(Path:GetClosestPosition(Player.Character.HumanoidRootPart.Position)) Path:ComputeAsync(Player.Character.HumanoidRootPart.Position, TargetPosition) Path:Wait() end for _, Waypoint in ipairs(Path:GetWaypoints()) do Player.Character.Humanoid:MoveTo(Waypoint.Position) Waypoint.Action = Enum.PathWaypointAction.Jump Path:WaitForWaypoint(Waypoint) end ClearPath() else Player.Character.Humanoid:MoveTo(TargetPosition) end end) Mouse.Button2Up:Connect(function() ClearPath() end) game:GetService("UserInputService"):BindAction("StopMovement", StopMovement, false, Enum.KeyCode.S)После внесения этих изменений код должен работать без ошибок.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.