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

Help making certain NPCs run away?

Asked by 8 years ago

Ever since ROBLOX removed negative walkspeeds that effectively invert controls for no reason, I've been desperately been trying to find a way to make certain NPCs run away. Here's my code.

local larm = script.Parent:FindFirstChild("Left Arm")

local rarm = script.Parent:FindFirstChild("Right Arm")



function findNearestTorso(pos)

    local list = game.Workspace:children()

    local torso = nil

    local dist = 50

    local temp = nil

    local human = nil

    local human2 = nil

    local temp2 = nil

    for x = 1, #list do

        temp2 = list[x]

        if (temp2.className == "Model") and (temp2 ~= script.Parent) then

            temp = temp2:findFirstChild("Torso")

            human = temp2:findFirstChild("Cop")

            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(0.1)

    local target = findNearestTorso(script.Parent.Torso.Position)

    if target ~= nil then

        script.Parent.Special:MoveTo(target.Position, -1)

    end

end

0
What is that spacing x.x Uroxus 350 — 8y
0
At line 9, children() doesn't exist use GetChildren() instead Kryddan 261 — 8y
0
can I get some other help...? especially with script.parent.special:moveto lncrediboy 0 — 8y

Answer this question