My NPC that I've created looks like it is lagging / teleporting while it is walking towards its target. Here is a video of what I am talking about: www.youtube.com/watch?v=I7xmUE8QkRw&feature=youtu.be
The YouTube link does work, but only if you copy and paste it =P
This is the code that I have that is located inside of him.
local npc = script.Parent
local hum = script.Parent.Humanoid
local humRP = script.Parent.HumanoidRootPart
local distance = 50
local function moveToPlayer()
local enemyFound = false
local WS = workspace:GetChildren()
if enemyFound == false then
for i, v in pairs (WS) do
if v:FindFirstChild("Humanoid") and v ~= npc and enemyFound == false then
if (v.HumanoidRootPart.Position - humRP.Position).Magnitude <= distance and enemyFound == false then
enemyFound = true
print("Enemy is close")
local plr = v
local plrHumRP = plr.HumanoidRootPart
local target = plrHumRP
return target
end
end
end
end
end
while true do
wait(.01)
moveToPlayer()
local targ = moveToPlayer()
if targ ~= nil then
hum:MoveTo(targ.Position)
end
end
Thank you everyone.
