Hello, I am currently making a TD game and I am having some problems with getting the enemies to move along the track.
Currently I am using :MoveTo() to get the enemies to move to the next waypoint, but there is a brief pause from when I call :MoveTo() to when the enemy actually moves.
At first I used Humanoid.MoveToFinished:Wait() to time the movements, and I thought that this was causing the delay, which caused me to switch a system where I use RunService.Heartbeat to constantly check the NPC’s position to see when it has reached the next point, this however yielded the same results leading me to believe that the timing of the movements is not the problem.
I think the problem is with :MoveTo() or Humanoid.WalkToPoint.
Faster Enemies move just fine along the track, but slower enemies pose a problem, meaning there are workarounds but I would prefer to solve the issue instead of just working around it.
I suspect it is a server-side issue as when i play in studio there is no delay, but when I play in an actual roblox server the delay is present.
Here is the code I am using to move the NPC:
-The waypoints are stored as Vector3 positions in a table called “navPath”
-This is a Server Script inside the NPC.
RunService.Heartbeat:Connect(function()
local nextPoint = nextPointVal.Value + 1
local np = navPath[nextPointVal.Value]
local distToPoint = (hrp.Position - Vector3.new(np.X, hrp.Position.Y, np.Z)).Magnitude
if distToPoint <= towerFuncs.zombieMovementThreshold then
if nextPoint == #navPath+1 then
miscFolder.BaseHealth.Value -= hum.Health
zombie:Destroy()
else
nextPointVal.Value = nextPoint
hum:MoveTo(navPath[nextPoint])
end
end
end)
I also have a video of the problem where you can see the delay:
https://www.youtube.com/watch?v=KzfefIGC9WY
I have also tried moving the NPC on the client which didn’t work at all.
Any and all help greatly appreciated!
Thanks!
** EDIT
What I’m hearing is that while there are ways to mitigate this issue, it’s better to use something like TweenService or Lerp, as they use less memory and should yield the same results. Thank you all who replied and gave your feedback, you have been immensely helpful!