[SOLVED] "Attempt to index nil with Position" in pathfinding function

I’ve triple checked the server side, function, and call, and I’m definitely sending the npc’s model as “npc” in all areas.


Server Side

image


Client Side

image


Edit

I have a function for an alert status that also uses npc.PrimaryPart, and that works just fine, the only difference being that it’s in a table.


Server Side


Client Side

Edit 2
All server examples are inside one script and using the same variables, and all client examples are in the same script, using the same sent variables as shown in the server screenshots. The NPC is being returned properly, however the invokedNeutral example continues to be adamant that the RootPart’s position doesn’t exist.

1 Like

What exactly is the PrimaryPart?

HumanoidRootPart.

I’ve also tried swapping with FindFirstChild/WaitForChild(‘HumanoidRootPart’) and the same error appears.

I have a separate function for an alert status that works just fine with npc.PrimaryPart.

1 Like

You shouldn’t send a function like that, just do this instead

local finalPos 
if math. random(1,2) = 1 then finalPos = pos else finalPos = pos2 end
move(npc, finalPos, false, 0

Didn’t do anything, and the line with the ternary operator isn’t where the error is occurring anyhow.

Maybe do :FindFirstChild(“PrimaryPart”) instead of HRP like this:

local npcRoot = npc:FindFirstChild("PrimaryPart")

Oops I made typos in the code, try this (on the third script, not on error line)

local finalPos 
if math. random(1,2) == 1 then finalPos = pos else finalPos = pos2 end
move(npc, finalPos, false, 0)

Yea try what the person above says too

That wouldn’t work with the rig I’m using, it’s a standard R15 and FindFirstChild(‘PrimaryPart’) would look for a part named “PrimaryPart,” rather than the model’s actual primary part, HumanoidRootPart.

Nothing on both counts. FindFirstChild(‘PrimaryPart’) broke the alert function bc there’s no part named “PrimaryPart” in the NPC, and returned nil, so that’s definitely not it lol

[SOLVED]

Combined the remote functions into one, added parameters to tell the remote function which state the NPC swaps to, and simply used this in areas needed.

local npcRoot = npc:FindFirstChild('HumanoidRootPart') or npc:WaitForChild('HumanoidRootPart')

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.