How to make this while loop smooth instead of buggy every 0.3 seconds

Hi! I was just testing the :MoveTo() function of an npc’s humanoid, and ran into a little bug.

Here is the script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
while true do
		Humanoid:MoveTo(player.Character.Torso.Position)
		script.Parent.Humanoid.WalkSpeed = script.Parent.Humanoid.WalkSpeed + 1
		wait()
	end
end)

My issue is that I want the npc to constantly follow you smoothly, but the “wait()” in the while loop makes it follow you in a glitchy manner. Can anyone help me solve this please?

1 Like

Replace this with task.wait.

1 Like

Thanks for the reply. I added this in, but when the npc gets close to you, he starts getting a little glitchy. Is there any way to fix that? Also I added it so he gets progressively faster as time progresses in the previous script.

You could tween the walk speed

Thanks. How can I do this? Because I don’t want the npc to start glitching while he walks near you, I just want him to keep walking straight to you, even maybe past you so he doesn’t stop and start glitching if u know what I mean

Well the NPC always moves to your position so its not going to go past you at any time.