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

How do you get an enemy NPC to follow the player?

Asked by 3 years ago
Edited 3 years ago

Disclaimer (I'm very new to coding within Roblox and 90% of my game code is from the toolbox, and the battledroid I'm using is also from there; hence my being confused on how to fix it)

The Battledroid NPC won't attack me, but will attack a "drooling zombie". All I need for the Battle Droid to do is to follow me because it already does damage upon touching the player, and it will already shoot and damage the player. - - Could other scripts within my game be affecting it's response? I already deleted the spawn protection wall because I thought it might be messing with it. But it's probably the code which I'll add underneath. Thanks for any help!!

(Btw this is the link to the game: https://www.roblox.com/games/4931576856/Star-Wars-The-Citadel-Challenge)

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 = 500
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("Right Arm")
15            human = temp2:findFirstChild("Humanoid")
View all 38 lines...
0
drooling zombie is have Humanoid too that why it attack drooling zombie you need to script to make script know you need to make it attack player not just humanoid Trorapantest1 13 — 3y
0
How would I make the npc know its a player tho? Just replace Zombie with Humanoid?? mississippiono 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

human = script.Parent:findFirstChild("Humanoid") if human == nil then human = script.Parent:findFirstChild("Zombie") end

it should be a Humaniod at zombie

0
The [if human == nil then human = script.Parent:findFirstChild("Zombie") end] code checks if its a humanoid and if not then checks for a zombie. What I need is for it to find a player mississippiono 0 — 3y
Ad

Answer this question