Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I go about making an NPC hostile?

Asked by 7 years ago

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.

0
I think it's an option, unsure, have you checked the dev wikia? Twenty1chickens 4 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I don't know what your variables are but feel free to use this. This is a follow & damageable script

01local larm = script.Parent:FindFirstChild("Left Arm")
02local rarm = script.Parent:FindFirstChild("Right Arm")
03 
04function 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 temp2 = nil
11    for x = 1, #list do
12        temp2 = list[x]
13        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
14            temp = temp2:findFirstChild("Torso")
15            human = temp2:findFirstChild("Humanoid")
View all 44 lines...

Here is a npc health script if needed (Grabbed off of wiki)

01function 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 
View all 28 lines...
0
Thanks! But if you can, could you also please explain to me what each part in the follow/damage script do? SweetNoodleSoup 14 — 7y
0
SweetNoodleSoup, The Follow script is a simple noticePlayer script. Damage script declares the amount of damage it will do to the player on contact ZapherosX 43 — 7y
Ad

Answer this question