Hello! I decided to make really weird game because I was bored, and I want an npc to chase after you. I have code for it, except it is not working. No error is given. Here is the code:
function findNearestTorso(pos) local torso = nil local dist = 99999999999999999999999999999999999999999999999999999999999999999999999999 local temp2 = nil local temp = nil local list = workspace:GetChildren() for x = 1, #list do temp2 = list[x] temp = temp2:FindFirstChild('Torso') or temp2:FindFirstChild('UpperTorso') if temp then if (temp.Position - pos).Magnitude < dist then torso = temp dist = (temp.Position - pos).Magnitude end end end return torso end local target = findNearestTorso(script.Parent.UpperTorso.Position) local pfs = game:GetService("PathfindingService") local path = pfs:CreatePath() local waypoints = path:GetWaypoints() path:ComputeAsync(script.Parent.UpperTorso.Position, target.Position) for _, v in pairs(waypoints) do if v.Action == Enum.PathWaypointAction.Jump then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) end script.Parent.Humanoid:MoveTo(v.Position) script.Parent.Humanoid.MoveToFinished:Wait(2) end