Hello, I would like to know what’s wrong with my Pathfinding robot.
Its a Humanoid body, with the robot on the head motored on it.
It should follow you, but instead it spins huge circles or glitches behind or infront of you.
local hrp = script.Parent.HumanoidRootPart
hrp:SetNetworkOwner()
local function Follow()
if not script.Parent.FindTarget.Aggressive.Value then
local distance = 100000
local nearestPosition
for _, player in ipairs(players:GetPlayers()) do
local Owner = script.Parent.Drone.Owner
local target = workspace[Owner.Value].PrimaryPart
if target then
local magnitude = (target.Position - hrp.Position).Magnitude
if magnitude <= distance then
distance = magnitude
nearestPosition = target.Position
end
end
end
script.Parent.Humanoid:MoveTo(nearestPosition)
end
end
while true do
Follow()
task.wait(0.2)
end```
Footage:
https://gyazo.com/cfa1f20780c1e1001be084b66af2b1e8