Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

NPC Pathfinding script isn't working as intended?

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

5 comments

0

I'm new to this site and didin't really knew how the text worked, sorry.

0

are you nuts

0

Try to search a path finding system in the toolbox.

0

It looks like a zombie script. Are you trying to make it go to a player but its not working, Just search a zombie in toolbox, Copy its scripts and Folder(if there is any) and put it in your creature

0

didint help

1 answer

I think I have found the issue, I did something wrong with the MoveTo script.

1 comment

0

It's still doing nothing..

This discussion is preserved as it was. New answers, comments, and votes are closed.