Should the Npc track the player using a Loop?

Hello,

I am currently working on how the Npc should chase the player.

My script is server sided since the npc can walk to points only on the server and i know that its not really a good idea to put loops in the server, but is puting a loop to handle the npc’s chase script good?

Is there a better way of it, if not how much time should be waited after each loop so the game wont lag?

Any suggestion whould be greatly appreciated!!!

That’s really the only way of doing it

1 Like

Sure, it should loop, but not using regular loops like for or while. Make use of the Heartbeat instead.

1 Like

Why not while loop? I would like to know more

1 Like

iirc, heartbeat is the exact same thing as a while task.wait() do loop

1 Like

Oh yes, it is indeed in terms of performance, my bad! I still prefer it because of its deltaTime.

2 Likes

I like it because it’s easier to attach it onto a connection and disconnect later :stuck_out_tongue:

2 Likes