So I am currently trying to make an enemy NPC that when you get close to it, it chases you and attacks you. Then after chasing you for a set distance, it will return back to its original position. However, I don't know where to start. I am aware that I am not providing a script to be fixed, but I would highly appreciate it if someone could point me in the right direction. Please help and thank you.
I don't know what your variables are but feel free to use this. This is a follow & damageable script
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" ) |
Here is a npc health script if needed (Grabbed off of wiki)
01 | function waitForChild(parent, childName) |
02 | local child = parent:findFirstChild(childName) |
03 | if child then return child end |
04 | while true do |
05 | child = parent.ChildAdded:wait() |
06 | if child.Name = = childName then return child end |
07 | end |
08 | end |
09 |
10 | -- declarations |
11 |
12 | local Figure = script.Parent |
13 | local Head = waitForChild(Figure, "Head" ) |
14 | local Humanoid = waitForChild(Figure, "Humanoid" ) |
15 |