I am trying to make a following npc, can someone help me? I am a beginner scripter and this is my first time trying to make a following script and cant figure out how plz help :C
There
01 | local list = game.Workspace:children() |
02 | local dist = 500 -- Change to the distance you want the Zombie to find people |
03 | local time = 0.1 --Change to how long you want the Zombie to find and chase people (I recommend 0.1) |
04 |
05 | while true do wait(time) |
06 | for x = 1 , #list do |
07 | local temp 2 = list [ x ] |
08 | if (temp 2. className = = "Model" ) and (temp 2 ~ = script.Parent) then |
09 | local temp = temp 2 :findFirstChild( "Torso" ) |
10 | local human = temp 2 :findFirstChild( "Humanoid" ) |
11 | if (temp ~ = nil ) and (human ~ = nil ) and (human.Health > 0 ) then |
12 | if (temp.Position - script.Parent.Torso.Position).magnitude < dist then |
13 | script.Parent. --[[Zombies//Change to name of whatever you put this into]] :MoveTo(temp.Position, temp) |
14 | end --Then remove the text and these: -- [[ ]] |
15 | end |
16 | end |
17 | end |
18 | end |
Here try this, make sure it's in a model with a Humanoid, and also make sure the model is not anchored.
01 | local larm = script.Parent:FindFirstChild( "Left Arm" ) |
02 | local rarm = script.Parent:FindFirstChild( "Right Arm" ) |
03 |
04 | function findNearestTorso(pos) |
05 | local list = game.Workspace:children() |
06 | local torso = nil |
07 | local dist = 1000 |
08 | local temp = nil |
09 | local human = nil |
10 | local temp 2 = nil |
11 | for x = 1 , #list do |
12 | temp 2 = list [ x ] |
13 | if (temp 2. className = = "Model" ) and (temp 2 ~ = script.Parent) then |
14 | temp = temp 2 :findFirstChild( "Torso" ) |
15 | human = temp 2 :findFirstChild( "Humanoid" ) |