Need help with an NPC

1)I’ve been trying to make an NPC chase a player, using a script of someone named V3N0M_Z

  1. The script contains the code to move an NPC to a location, but I can’t figure out how to move to a player, the problem is in the third local

  2. The script is changed there because I was trying to figure it out myself. image

1 Like

game.Players is not a part. I wouldn’t recommend blindly copying scripts from online without understanding the underlying code.

You should learn some of the basic concepts behind scripting and the ROBLOX API/environment before modifying someone else’s script.

Uh, it seems like you’re destroying a path before even using it? Not too sure?
I don’t even know how the module works since it’s an ID, so it’s probably not even open source or anything.

I would honestly recommend just looking at the pathfinding documentation
and not rely on someone else’s module,
a simple pathfinding is relatively simple to do.

You create a path object with PathfindingService.

The function CreatePath() requires a simple table as argument.

The table looks something like this:

local agentparams = {
 AgentRadius = 2;
 Agentheight = 5;
 AgentCanJump = true;
}

You can adjust any of these values based on how big your NPC is and such.

After calling this function it will return an object/instance that has the function :ComputeAsync().

This function simply requires a start (Vector3) and goal (Vector3) so it knows where to start and where to end it’s calculation.

I could not think of a simpler way to do pathfinding in Roblox tbh, it’s a single function that requires a start and goal.

After the path is finished (it yields/waits until the path is done) you can call :GetWaypoints()
which will return a table containing points which each have a position (Vector3) and a action (Enum),
all these points should always be in order so you can just loop through this table using ipairs/for i/whatever loop you prefer.

Just make sure you wait until a point is reached before moving onto the next one or you may still end up walking into walls, but this should be relatively simple to pull off.

The API even has a function/event for recalculating a path when it’s blocked, however that’s another story and if your game doesn’t have a lot of moving objects it’s likely not needed most of the time.

Hope this helps you out a bit.

Edit: for any other scripter out there, feel free to correct me if I’m wrong on something, although I’m mostly certain that this is right.