Robot returning to dock

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

. The whole thing is unanchored. It’s a skid steer robot on two wheels and it has a castor wheel at the front.

Looking at your code I can’t see anything that jumps out at me.
Have you tried it on a default character model? If it works on that, then you can confirm that the error is something to do with how the robot model is built.

losense.rbxm (35.8 KB)
here’s the file if you want it. Please don’t steal it or save it to your inventory.

Ok, I took a look at it and got it to work.
For starters, you need to enable EvaluateStateMachine inside the humanoid in order to move it. You’ll also probably want to increase the HipHeight so it is not colliding with the ground.

Also, it wouldn’t work until I disabled the motors. Setting MotorMaxTorque and AngularVelocity to 0 isn’t enough.

Let me know if you can get it working.

It is like one of these: irobot Roomba - Creator Store. The model here does not have a head, just the humanoid instance and the HumanoidRootPart.

It’s moving but it’s spinning around, i can’t upload a video because it is too big. I want it to move towards the dock, but with the spinning it does not move towards the station properly

That’s fine, not having a head shouldn’t affect anything.

I think you might have to increase the HipHeight in the humanoid. The spinning is probably caused by the robot colliding with the floor.

the robot’s case size is 3.142, 0.518, 2.843 (X,Y,Z), and when i set the wheels to ActuatorType.None it still goes into a spin. EvaluateStateMachine is activated. Will PlatformStand prevent it from moving?

Unfortunately, humanoids don’t work very well with hinge constraints.

When I tested it, setting ActuatorType to None did not work. I had to set Enabled to false. When I did that though, the wheels fell off. You could probably fix that by welding the wheels whenever you disable the motors.

I don’t think PlatformStand should affect anything.