MoveToFinished delaying, any alternatives?

MoveToFinished seems to be delayed. I have tried every combination but the movement is always choppy/stuttering so I don’t think this is a code issue anymore. I already set all of the model’s BasePart’s networkship to nil so this shouldn’t be a network issue, if anyone has a solution or a good alternative to MoveToFinished then please tell me so!

1 Like

It should be smooth as. It can be slow to timeout to the next move as it is an 8 second duration. When setting the Network Owner, you only need to set that on the Primary Part:

<yourNPC>.PrimaryPart:SetNetworkOwner(nil)
1 Like

If you want to use MoveToFinished but also override it’s 8 second timeout, you can make your own function.

local function MoveToFinished(hum: Humanoid, timeout: number): boolean
	local event: BindableEvent = Instance.new("BindableEvent")
	local success: boolean = true

	task.delay(timeout, function() 
		success = false 
		event:Fire() 
	end)
	task.defer(function() 
		hum.MoveToFinished:Wait() 
		event:Fire() 
	end)

	event.Event:Wait()
	event:Destroy()
	return success
end

This is what I mean when it “stutters”. In the video, the Text tells the amount of velocity magnitude of the model’s HumanoidRootPart. You can see that it decreases randomly back and fourth. (Excuse for the crappy quality as I’m using Roblox’s recorder)

robloxapp-20220810-1602541.wmv (2.6 MB)

The Code I used is

local AI = script.Parent;
local Goal = workspace:WaitForChild("Goal");

local Path = game:GetService("PathfindingService"):CreatePath({
	AgentHeight = AI:WaitForChild("Humanoid").HipHeight,
	AgentRadius = AI:WaitForChild("HumanoidRootPart").Size.X,
	AgentCanJump = true
});

for index, v in pairs(AI:GetChildren()) do
	if (v:IsA("BasePart"))then
		if (v:CanSetNetworkOwnership(v)) then
			v:SetNetworkOwner(nil);
		end;
	end;
end;

local function GetHumanoidPosition()
	return (AI:WaitForChild("HumanoidRootPart").Position - Vector3.new(0,AI:WaitForChild("Humanoid").HipHeight,0))
end;

local function ChangeYPositionToRootPart(vector)
	return (Vector3.new(vector.X, AI:WaitForChild("HumanoidRootPart").Position.Y, vector.Z))
end;

function Move()
	for index, v in pairs(Path:GetWaypoints()) do
		if (index > 1) then
			AI:WaitForChild("Humanoid"):MoveTo(ChangeYPositionToRootPart(v.Position));
			AI:WaitForChild("Humanoid").MoveToFinished:Wait();
		end;
	end;
end;

function CreatePath(destination)
	Path:ComputeAsync(GetHumanoidPosition(), destination);
	if (Path.Status == Enum.PathStatus.Success) then
		Move();
	end;
end;

CreatePath(Goal.Position);

I don’t see any problems with this code? Unless I’m wrong.

I’ve heard that setting all of the model’s Base Part is better than setting the Primary Part alone. But thank you for that information.

Use :Wait() in a Stepped loop.