In this script, it detects a player, then moves an NPC to it. Everything seems to be working, but the NPC doesn't move. What am I doing wrong?
01 | local larm = script.Parent:FindFirstChild( "HumanoidRootPart" ) |
02 | local rarm = script.Parent:FindFirstChild( "HumanoidRootPart" ) |
03 |
04 | function findNearestTorso(pos) |
05 | local list = game.Workspace:children() |
06 | local torso = nil |
07 | local dist = 10000 |
08 | local temp = nil |
09 | local human = nil |
10 | local temp 2 = nil |
11 |
12 |
13 | for x = 1 , #list do |
14 |
15 | temp 2 = list [ x ] |
Thanks!
Using standard pathfinding would work but would have some flaws. If you want to detect when a player joins a game a simple
[npcname].Humanoid:MoveTo(game.Players.[playername or localplayer])
but if you want it to move when the player gets a certain distance to it then a testfor a humanoid within a certain stud radius would work fine too.