Move to is lagging. Basically what happens is that, when the player keeps moving forward, the NPC moves to its position, but before it reaches it, the player is already further than the NPC, therefore making it laggy, because the npc stops, waiting until its told to :MoveTo() again, and the script doesnt just happen in a nanosecond.
for i,v in game.Players:GetPlayers() do
print("PlayerFound")
if v.Character.Parent == game.Workspace.Characters then
print(v,v.Character,v.Character.Parent)
local PlayerPosition = v.Character.PrimaryPart.Position
local RakePosition = Rake.PrimaryPart.Position
if (RakePosition - PlayerPosition).Magnitude < 50 then
local raycastparams = RaycastParams.new()
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
raycastparams.FilterDescendantsInstances = {Rake}
local direction = PlayerPosition - RakePosition
local raycast = workspace:Raycast(RakePosition,direction,raycastparams)
print(RakePosition,PlayerPosition)
print("Raycasted")
print(raycast.Instance,raycast.Instance.Parent.Parent,raycast.Instance.Parent)
if raycast.Instance.Parent == v.Character then
print("Found")
hum.WalkSpeed = RunSpeed
while true do
task.wait()
hum.MoveToFinished:Connect(function(reached)
bool = true
end)
local function Normal()
if bool then
local raycastparams = RaycastParams.new()
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
raycastparams.FilterDescendantsInstances = {Rake}
local raycast = workspace:Raycast(Rake.PrimaryPart.Position,v.Character.PrimaryPart.Position,raycastparams)
TargetPosition = v.Character.PrimaryPart.Position
if raycast.Instance.Parent == v then
hum:MoveTo(v.Character.PrimaryPart.Position)
print("Moving to")
else
followPath(v.Character.PrimaryPart.Position)
print("Following path")
end
end
end
if (Rake.PrimaryPart.Position - v.Character.PrimaryPart.Position).Magnitude > 50 then
print("Too far away")
task.wait(5)
if (Rake.PrimaryPart.Position - v.Character.PrimaryPart.Position).Magnitude > 50 then
print("Ended")
hum.WalkSpeed = NormalSpeed
break
else
Normal()
end
else
Normal()
end
end
end
end
end