Clone the enemy and place the enemy into workspace
set the network owner of the clone to the player the enemy is chasing
tell the client somehow that they need to control the enemy maybe in a remote event or set a attribute on the enemy
in a localscript for only the client who is controling the enemy they need to set the enemy’s Humanoids MoveTo function the server should not be calling the MoveTo function
When a client has network ownership then that client will tell the server the position and velocity of the enemy and the server will tell all other clients
This is also how the players character works
If you set the players character network owner to nil then the player will become laggy
In this video I talk about network ownership it might be a good thing to watch
And I also talk about network ownership in this video a little
Don’t use .MoveToFinished:Wait(), the delay between the time the humanoid stops moving and the actual event firing is quite noticeable.
What you want to do is a magnitude check to detect whether your humanoid is close enough to its current waypoint.
local timeOut = false
local toWaypoint = (primarypart.Position - waypoint.Position) * Vector3.new(1,0,1)
while toWaypoint.Magnitude < 5 do
toWaypoint = (primarypart.Position - waypoint.Position) * Vector3.new(1,0,1)
task.wait(0.2)
end
Of course this could yield indefinitely, so you’ll want a ways to prevent this:
Have a timestamp for every ‘Move here’ command, so the code knows when to stop this loop.
Something to replace timeOut with in .MoveToFinished:Wait()
So, here’s a fixed code;
if path.Status == Enum.PathStatus.Success then
local now = os.clock()
myHuman:SetAttribute("_lastMove", now)
for _, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
local timeElapsed = 0
local timeoutTime = 8; -- 8 secs
local timeout = false
local toWaypoint = (primarypart.Position - waypoint.Position) * Vector3.new(1,0,1)
while toWaypoint.Magnitude < 5 and myHuman:GetAttribute("_lastMove") == now and timeElapsed < timeoutTime do
toWaypoint = (primarypart.Position - waypoint.Position) * Vector3.new(1,0,1)
timeElapsed += task.wait(0.2)
end
if timeElapsed > timeoutTime then
timeout = true
end
if not timeout then
--print("Got stuck")
myHuman.Jump = true
walkRandomly()
end
end
else
--print("Path failed")
wait(1)
walkRandomly()
end
Pathfinding issue most likely. My quick suggestion would be to try and set it’s target in front of the player with about 15 studs. So, it will try and walk through players, and in this way kill them.
Oh, I meant the PrimaryPart of your NPC Killer character, since you want to get the distance between your character (the one which is pathfinding, in your case the NPC Killer) to its current waypoint.