Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local…

  1. 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)
    end
    

    end)

    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") Подкорректируй скрипт.

  2. 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)
    

    После внесения этих изменений код должен работать без ошибок.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.