Pathfinding help

local pfs = game:GetService("PathfindingService")
local path = pfs:CreatePath()
path:ComputeAsync(v.HumanoidRootPart.Position, plrhrp)
local waypoints = path:GetWaypoints()
if waypoints[#waypoints].Position ~= plrhrp then

for some reason position is index nil (this isnt full script)
i cant find any solution

1 Like

Define plrHRP. Also what is nil? The target hrp?

1 Like

ok so im trying to make the script follow the person i say so plrhrp is the person’s humanoidrootpart of who i say also the nil part is the position after i get the last waypoint and idk why

1 Like

Alright thanks. Can you give me the variable for the player hrp please. I think thats where the issue is.

1 Like

game.Players.GreySkiesofSpace.Chatted:Connect(function(msg)
	local String = msg
	local split = string.split(String, " ")
	if split[1] == "follow" then
		while wait() do
			if split[2] == "me" then split[2] = "GreySkiesofSpace" end
			if game.Players:FindFirstChild(split[2]).Character.HumanoidRootPart ~= nil then
				local plrhrp = game.Players:FindFirstChild(split[2]).Character.HumanoidRootPart.Position
1 Like

also im pretty sure its not the plrhrp part because the move to works and i use the plrhrp in the computeasync function

1 Like

Ahaha! Don’t set the position there. Update it everytime. Like


path:ComputeAsync(v.HumanoidRootPart.Position, plrhrp.Position)

It’s a loop right?

1 Like
if waypoints[#waypoints].Position ~= plrhrp then 
							path = pfs:CreatePath()
							path:ComputeAsync(v.HumanoidRootPart.Position, plrhrp)
							waypoints = path:GetWaypoints()
						end

this is the full part of the statement
it might be the cause

1 Like

yeah it is a loop but i alr have that

1 Like

Also this might be nil. Sorry for bad typing on mobile

1 Like

how it nil though :confused: it finds the last waypoint doesnt it?

1 Like

also i tried that but it unreliable and it hardly updates the loop xd probably because i dont use .movetofinished because it makes the npcs pathfind one at a time

Mb. Im rushing. The best I can guess is that the position isn’t updating do:


local plrhrp = game.Players:FindFirstChild(split[2]).Character.HumanoidRootPart

``
Also what are you trying to do?
1 Like

make all the npcs in folders in a folder follow a certain player i specify using a chat message

1 Like

Is it okay if I change the whole script? I cant really help sorry. Im notbsure

1 Like

uh sure want me to send the whole script?

1 Like

Not a whole script just the basic movement. Give me a momment

1 Like

this?

for p,o in pairs(waypoints) do
							if v:FindFirstChild("Enemy") ~= nil then
								v.Enemy:MoveTo(o.Position)
								if o.Action == Enum.PathWaypointAction.Jump then
									v.Enemy.Jump = true
								end
							end
						end
2 Likes

I’m sorry for asking again but what is nil what object? I think the problem is the object is nil.

2 Likes

the last waypoint position or something idk what you sayin xd

1 Like