Humanoid:MoveTo() moving the humanoid when the powerful roblox god wants

Hello :wave: !

So for the past few hours now I’m trying to do an aggressive AI that chases player using PathfindingService. Sometimes it works very well, no issues. And then sometimes the rig just doesn’t move for the exact same goal position. Is it because I’m doing pathfinding ?

Here’s a piece of the code for the movement:

function m.Run(ai,target:Part) --ai is an object from another module. target is the target hrp
	local show_path = ai.settings.ShowPath

	ai.values.Attacking = true
	ai:SetGyroEnabled(false)

	local hrp:Part = ai.objects.hrp
	local humanoid: Humanoid = ai.objects.humanoid

	local path = ps:CreatePath({
		WaypointSpacing = 10,
		AgentCanJump = ai.settings.CanJump,
	})

	local succ, err = pcall(function()
		path:ComputeAsync(hrp.Position,target.Position)
	end)

	if succ then
		local waypoints = path:GetWaypoints()
		table.remove(waypoints,1) -- I removed it so the rig wont go too close from it's original position

		if show_path then
			for i, v in waypoints do
				local sphere = Instance.new("Part")
				game.Debris:AddItem(sphere,10)

				sphere.Material = Enum.Material.Neon
				sphere.Size = Vector3.one
				sphere.Shape = Enum.PartType.Ball
				sphere.Transparency = .7
				sphere.Anchored = true
				sphere.CanCollide = false
				sphere.CastShadow = false
				sphere.CanTouch = false
				sphere.Position = v.Position

				sphere.Parent = workspace
			end
		end
		
		for i, v:PathWaypoint in waypoints do
			humanoid:MoveTo(v.Position)
			if v.Action == Enum.PathWaypointAction.Jump then
				humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			humanoid.MoveToFinished:Wait()
		end
	end
end

And the result in both cases (both got the same goal position):

Working:
https://streamable.com/efu0zl
Not Working:
https://streamable.com/4ek11v

Can you help me plis :pensive: ?

1 Like

It looks like the issue might be related to how the path is being generated by PathfindingService. Even with the same goal position, factors like dynamic obstacles, uneven terrain, or silent failures in ComputeAsync can affect the path. Make sure the path is actually valid (path.Status == Enum.PathStatus.Complete) and that the Humanoid is in a state that allows movement. It’s also worth checking if anything is physically blocking the rig at runtime.

This is just my suggestion, but try looking at the script output/debug to see what is happening.

I just finished trying all of that, the path.Status returns Enum.PathStatus.Success, the path is clear and the humanoid seems to be able to move.

The path finds a way to go to the goal in the working and not working cases, so I think it might directly comes from humanoid:MoveTo().

1 Like

I’m so dumb…

You were right, I forgot to set back the humanoid WalkSpeed, it was set to 0 because of another AI state module (LookAround) and since the order of execution of the modules are random, if the this module comes first then it will work, and if the LookAround module comes first, the rig won’t walk to the position

Thanks for your help :+1: !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.