Laggy NPC movement (towards player)

Try this;

while true do
	local Target = GetClosestPlayer(400)
	print(Target)
	if Target ~= nil then
		if Target.Character ~= nil then
			Humanoid:MoveTo(Target.Character.PrimaryPart.Position)
			Humanoid.MoveToFinished:Wait()
		end
	else
		wait()
	end
end

Now we should only call a wait call once.
However, you are yeilding the next loop iteration until after either a wait() or a MoveToFinished:Wait().
Try this, and then see how it works, you may experience less stutter, but I think there will still be some.

3 Likes

I may be wrong or I may NOT be wrong, but I just encountered this problem. I noticed that it only happens when you get within a certain vicinity so it could be an issue with replication to client, etc. I solved it by iterating through the NPC, getting all BasePartā€™s, and doing BasePart:SetNetworkOwner(nil) to make the Server the network owner for the part. This eliminated the laggy choppy movement it used to have.

22 Likes

I wasnā€™t on ROBLOX dev for over a month but iā€™ll try this ;b

Funnily enough, this fixed the entire issue of this post and I somehow didnā€™t realize myself back then that this was an issue :slight_smile:

2 Likes

Iā€™m very late to this thread but thank you so much!