I want to make my robot move towards it’s dock. i’m having trouble getting the robot to move.
I have an image which shows what i’d like to achieve. When I call the function, it does not move at all.
I’d like to use PathfindingService to make the robot move to a part.
Here’s my script. (ReturnToDock, type is ModuleScript)
local PathfindingService = game:GetService("PathfindingService")
local ReturnToDock = {}
-- CONFIGURATION (Edit inside module only)
ReturnToDock.Config = {
RobotModel = script.Parent.Parent, -- Robot model (must contain Humanoid)
LeftMotor = script.Parent.Parent.LeftWheel.Motor.WheelMotor, -- Left wheel hinge motor
RightMotor = script.Parent.Parent.RightWheel.Motor.WheelMotor, -- Right wheel hinge motor
DockWaypoint = workspace.dock.WaypointPart, -- Dock target waypoint part
Speed = 6, -- Motor angular velocity (not used here but kept)
}
local function disableWheels(leftMotor, rightMotor)
if leftMotor and leftMotor:IsA("HingeConstraint") then
leftMotor.MotorMaxTorque = 0
leftMotor.AngularVelocity = 0
end
if rightMotor and rightMotor:IsA("HingeConstraint") then
rightMotor.MotorMaxTorque = 0
rightMotor.AngularVelocity = 0
end
end
local function stopHumanoid(humanoid)
humanoid:Move(Vector3.new(0, 0, 0))
humanoid:MoveTo(humanoid.RootPart.Position)
end
function ReturnToDock:Return()
local cfg = self.Config
assert(cfg.RobotModel, "RobotModel not set")
assert(cfg.LeftMotor, "LeftMotor not set")
assert(cfg.RightMotor, "RightMotor not set")
assert(cfg.DockWaypoint, "DockWaypoint not set")
local humanoid = cfg.RobotModel:FindFirstChildWhichIsA("Humanoid")
assert(humanoid, "No Humanoid found in RobotModel")
-- Disable wheels so they don't interfere with humanoid movement
disableWheels(cfg.LeftMotor, cfg.RightMotor)
-- Calculate path from robot's current position to dock waypoint
local startPos = cfg.RobotModel.PrimaryPart.Position
local endPos = cfg.DockWaypoint.Position
local path = PathfindingService:CreatePath()
path:ComputeAsync(startPos, endPos)
if path.Status ~= Enum.PathStatus.Success then
warn("[ReturnToDock] Failed to find path to dock!")
return
end
-- Follow each waypoint with humanoid MoveTo
local waypoints = path:GetWaypoints()
for i, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid:MoveTo(waypoint.Position)
local reached = humanoid.MoveToFinished:Wait()
if not reached then
warn("[ReturnToDock] Failed to reach waypoint ", i)
return
end
end
-- Stop humanoid movement once at dock
stopHumanoid(humanoid)
end
return ReturnToDock
I’ve tried numerous things. The first attempt lead to it moving away from it, not towards it. The model’s PrimaryPart is the HumanoidRootPart. Here’s my hierarchy

