You can write your topic however you want, but you need to answer these questions:
-
Goal
I want to make a smooth pathfinding script that follows the player instead of stays on the players head. -
What is the issue?
https://gyazo.com/b9c348f043b1b6ee5f60e5fbefffe184 – As you can see the NPC is on top of the players head when following the player. -
What solutions have you tried so far?
Changing parts in the script to see if it changed anything but it did not. Not sure what the problem is.
local leftarm = script.Parent:FindFirstChild("UpperTorso")
local rightarm = script.Parent:FindFirstChild("RootPart")
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 60
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(1)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent:MoveTo(target.Position, target)
end
end
If you could help that would be great!