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

How can I make an npc ignore a certain player and go to the next?

Asked by 2 years ago

Hi, I've been messing around with npcs from roblox that chase and attack you, but i've been trying to make it so you can summon an npc that attacks people for you when you use an ability, but the thing is, it doesn't go for the player, but if the player is closest to the noob it won't attack anyone else, as it only attacks the person closest to it, which in this case is the summoner.

In my script for summoning it, I put a string value inside the noob and made it say the name of the player because the chase script is inside the noob, not the summon script.

anyways, here is the chase script inside the noob. Help would be really appreciated!

local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
local summoner = script.Parent:WaitForChild("Owner")

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 10000
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
            temp = temp2:findFirstChild("HumanoidRootPart")
            human = temp2:findFirstChild("Humanoid")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if (temp.Position - pos).magnitude < dist then
                    torso = temp
                    dist = (temp.Position - pos).magnitude
                end
            end
        end
    end
    return torso
end




while true do
    wait(1)
    local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
    if target ~= nil and target.Parent.Name == summoner.Value then
        print("Target not found")   
    elseif target ~= nil and target.Parent.Name ~= summoner.Value then
        print("Target Found")
        script.Parent.Humanoid:MoveTo(target.Position, target)
    end

end

2 answers

Log in to vote
1
Answered by 2 years ago

Try using

if (temp2.className == "Model") and (temp2 ~= script.Parent) and temp2.Name ~= summoner.Value then
0
Thank you so much, it works! I feel stupid now lol DriBowser 55 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
if (temp2.className == "Model") and (temp2 ~= script.Parent) and temp2 ~= summoner.Value then
0
That didn't work. The noob still does what it used to do. Thanks for the response though! DriBowser 55 — 2y

Answer this question