Hi peoples. I am creating an NPC follow script and as you may know, if you add a while true do loop and just a wait() to it, it will be very laggy because of how many requests it gets. To solve this, all you need to do is add value to the wait. Now, if the player is far enough away from the NPC can you call the function every 2 seconds then the same thing will happen. That's why I thought of getting the distance of the NPC's humanoid root part and the distance of the character's humanoid root part and determining a waiting time based on that information. Except for all the times I have tried to do this, it has failed. Horribly. Usually returning a value of between 100 and 300. So I could really use some help on this one. Thanks <3
Here is a little example of what I've tried to do.
local npcRoot = npc.HumanoidRootPart
local playerRoot = player.HumanoidRootPart
local waitTime = (npcRoot.Position - playerRoot.Position).Magnitude
print(waitTime)
Again, I have no idea what I'm doing. I've used the Magnitude function before but never like this. Any help would be appreciated <3
