Humanoid MoveTo()

I’ve used the roblox pathfinding wiki and its code, after a while the character starts to stutter

Here is a video of the glitch
https://gyazo.com/be5101ceb42edac84ce286352f1cf39b

4 Likes

Could you please provide your code? Saying you used code from the wiki doesn’t help much since the wiki article you mention contains 12 different code blocks.

1 Like

local PathfindingService = game:GetService(“PathfindingService”)

– Variables for the zombie, its humanoid, and destination
local zombie = game.Workspace.Dummy
local humanoid = zombie.Humanoid
local destination = game.Workspace.Target

– Create the path object
local path = PathfindingService:CreatePath()

– Variables to store waypoints table and zombie’s current waypoint
local waypoints
local currentWaypointIndex

local function followPath(destinationObject)
– Compute and check the path
path:ComputeAsync(zombie.HumanoidRootPart.Position, destinationObject.Position)
– Empty waypoints table after each new path computation
waypoints = {}

if path.Status == Enum.PathStatus.Success then
	-- Get the path waypoints and start zombie walking
	waypoints = path:GetWaypoints()
	-- Move to first waypoint
	currentWaypointIndex = 1
	humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
else
	-- Error (path not found); stop humanoid
	humanoid:MoveTo(zombie.HumanoidRootPart.Position)
end

end

local function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
elseif reached and currentWaypointIndex == #waypoints then
wait(2)
followPath(destination)
end
end

local function onPathBlocked(blockedWaypointIndex)
– Check if the obstacle is further down the path
if blockedWaypointIndex > currentWaypointIndex then
– Call function to re-compute the path
followPath(destination)
end
end

– Connect ‘Blocked’ event to the ‘onPathBlocked’ function
path.Blocked:Connect(onPathBlocked)

– Connect ‘MoveToFinished’ event to the ‘onWaypointReached’ function
humanoid.MoveToFinished:Connect(onWaypointReached)

followPath(destination)

I just created a module for this and I believe it should help.

Well i don’t think it the path finding its the movement of the Humanoid, thats the issue… I’ve tried several different attempts and i keep getting the same results. it works for a couple of minutes and then it start to glitch.

The module uses pathfinding and MoveTo. I have yet to receive any issues with the moving

i am experiencing the same issues but i think

humanoid.MoveToFinished:wait()

breaks it
i removed it then it didnt glitch anymore

1 Like

Try this:

for _, v in pairs(zombie:GetChildren()) do
	if v:IsA("BasePart") then
		v:SetNetworkOwner(nil)
	end
end

Let me know how it goes.

Yah I thought that to but deleted my message since I realised something. He’s testing in studio run mode so the server will always have ownership, theirs no time where the network ownership goes to the client since there is no client connected at the first place, so network ownership will always be in the server in this case, (until he tests in studio run mode).

Basically that isn’t the problem.

1 Like

I dont use this could it be the MoveToFinished function “:connect()” as well?

When I used pathfinding for the first time, I used the wiki and it worked fine. I don’t think the MoveToFinished breaks the code.

2 Likes

Youre Module for the pathfinding dosent seem to work at all, i set prams and then i ask to move and it gives me a error for [function onWaypointReached]

Sorry. Something went wrong in the new update I released. It should be fixed now! Tell me if it works.

1 Like

Can you just try doing:

  Zombie.HumanoidRootPart:SetNetworkOwner(nil)

I’m on mobile so i cant format, sorry.

Like others have mentioned, it could due to humanoid.MoveToFinished:wait()

There is a chance, that your humanoid briefly stops between each waypoints. What you can do instead is check the distance between the HumanoidRootPart and the next waypoint, using magnitude. Once the distance between those two points are covered, tell the humanoid to move to the next waypoint.

local distance
     repeat
         distance = (waypoints[currentWaypointIndex].Position -
         zombie.HumanoidRootPart.Position).Magnitude
         wait()
    until
        distance <= (Any_Number)
 end
1 Like

Now im getting a error after the fourth time i move the dummy, MainModule:92: attempt to index nil with ‘Position’

May be try this code

local Npc = script.Parent
local Humanoid = script.Parent.Humanoid
local PathfindingService = game:GetService("PathfindingService")

local function getPath(destination)
	local pathParams = {
		["AgentHeight"] = 5.15, -- change this to your NPC Height 
		["AgentRadius"] = 4	-- change this to the width of your npc
						}
	
	local path = PathfindingService:CreatePath(pathParams)

	path:ComputeAsync(Npc.HumanoidRootPart.Position, destination.Position)
	
	return path	
end

local function walkTo(destination)
	
	local Path = getPath(destination)
	
	if Path.Status == Enum.PathStatus.Success then
	for index, waypoint in pairs(Path:GetWaypoints()) do 

			Humanoid:MoveTo(waypoint.Position)
			Humanoid.MoveToFinished:Wait()
			
			
		end
	else
		Humanoid:MoveTo(destination.Position - (Npc.HumanoidRootPart.CFrame.LookVector * 10))
	end
end

function patrol()
	local Target = workspace.Target -- change this to the part where the NPC is moving 
	walkTo(Target)
end
while wait(0.5) do 
	patrol()
end	

This doesn’t seem to work. still has a choppy movement

Try:

zombie.PrimaryPart:SetNetworkOwner(nil)

Put this at the beginning of your script, after defining your zombie.

2 Likes

Does your character have a welded part(like a tool or something?).
This has happened to me too.

And like @Little_Joes said add a zombie.PrimaryPart:SetNetworkOwner(nil).
But add it before the NPC starts to move

1 Like