:MoveTo() Problem

Hi, for strange reason my script doesn’t work and I don’t understand at all what is the issue because the position is good but when I want to do :MoveTo() it doesn’t work !
Here the script :

local PathfindingService = game:GetService("PathfindingService")
local Character = script.Parent
local Humanoid = Character.Humanoid
local Left = workspace:WaitForChild("Left"..Character.Name)
local Right = workspace:WaitForChild("Right"..Character.Name)
local Path = PathfindingService:CreatePath({
	AgentRadius = 2,
	AgentHeight = 5,
	AgentCanJump = false
})

while wait() do
	local CharacterPosition = Character.PrimaryPart.Position
	local LeftPosition = Left.Position
	local RightPosition = Right.Position
	local LeftMagnitude = (CharacterPosition - LeftPosition).Magnitude
	local RightMagnitude = (CharacterPosition - RightPosition).Magnitude
	if LeftMagnitude < RightMagnitude then
		Path:ComputeAsync(CharacterPosition, LeftPosition)
		local PathWaypoints = Path:GetWaypoints() 
		Humanoid:MoveTo(PathWaypoints[1].Position)
	elseif LeftMagnitude > RightMagnitude then
		Path:ComputeAsync(CharacterPosition, RightPosition)
		local PathWaypoints = Path:GetWaypoints() 
		Humanoid:MoveTo(PathWaypoints[1].Position)
	end
	Humanoid.MoveToFinished:Wait()
end

Thanks for the reply and have a nice day !

I had to correct your script on my side and I managed to solve it by adding :WaitForChild(“Humanoid”) after Character

try this maybe

local PathfindingService = game:GetService("PathfindingService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Left = workspace:WaitForChild("Left"..Character.Name)
local Right = workspace:WaitForChild("Right"..Character.Name)
local Path = PathfindingService:CreatePath({
	AgentRadius = 2,
	AgentHeight = 5,
	AgentCanJump = false
})

while wait() do
	local CharacterPosition = Character.PrimaryPart.Position
	local LeftPosition = Left.Position
	local RightPosition = Right.Position
	local LeftMagnitude = (CharacterPosition - LeftPosition).Magnitude
	local RightMagnitude = (CharacterPosition - RightPosition).Magnitude
	if LeftMagnitude < RightMagnitude then
		Path:ComputeAsync(CharacterPosition, LeftPosition)
		local PathWaypoints = Path:GetWaypoints() 
		Humanoid:MoveTo(PathWaypoints[1].Position)
	elseif LeftMagnitude > RightMagnitude then
		Path:ComputeAsync(CharacterPosition, RightPosition)
		local PathWaypoints = Path:GetWaypoints() 
		Humanoid:MoveTo(PathWaypoints[1].Position)
	end
	Humanoid.MoveToFinished:Wait()
end
1 Like

Thanks you very much but it’s doesn’t work !