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

How i can make that the NPC changes his speed when he is following you?

Asked by 6 years ago

i have a little problem, How i can do that when the NPC are following you, its speed changes?

Here is the script

function findNearestTorso(pos)  --  declare pos a local vector3
    local list = game.Workspace:children()
    local torso = nil
    local dist = 25  -- Area to search
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if temp2.className == "Model" then
            temp = temp2:findFirstChild("Torso")
            if temp ~= nil then
                human = temp2:findFirstChild("Humanoid")
                if human ~= nil and (human.Health > 0) and (temp2.Name ~= AIName) then -- not named the same as us.
                    if (temp.Position - pos).magnitude < dist then
                        torso = temp
                        dist = (temp.Position - pos).magnitude
                    end  --  closer?
                end   --  human? Not us. 
            end -- Has torso?
        end   --  Model? 
    end  --  For. Loop thru parts in Workplace

    return torso
end  -- findNearest
0
clearly you stole the script... and clearly if u wrote this, you would know the answer greatneil80 2647 — 6y
0
^^ MakeYourEscape 334 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

just get the npc's humanoid

local NPC = script.Parent
local HumanoidOfNpc = Npc:FindFirstChild("Humanoid")
local speed = 20
function findNearestTorso(pos)  --  declare pos a local vector3
    local list = game.Workspace:children()
    local torso = nil
    local dist = 25  -- Area to search
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if temp2.className == "Model" then
            temp = temp2:findFirstChild("Torso")
            if temp ~= nil then
                human = temp2:findFirstChild("Humanoid")
                if human ~= nil and (human.Health > 0) and (temp2.Name ~= AIName) then -- not named the same as us.
                    if (temp.Position - pos).magnitude < dist then
                        torso = temp
                        dist = (temp.Position - pos).magnitude
            HumanoidOfNpc.WalkSpeed = speed
                    end  --  closer?
                end   --  human? Not us. 
            end -- Has torso?
        end   --  Model? 
    end  --  For. Loop thru parts in Workplace

    return torso
end  -- findNearest

This should help you define NPC and HumanoidOfNpc and speed for results

Ad

Answer this question