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

how do i make the NPC follow me as a player?

Asked by 3 years ago

hello scripter's and helper's i need some help with this script:

function findNearestPlayer(Position)
    wait(0.3)
    local List = game.Workspace:children()
    local Torso = nil
    local Distance = 250
    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 - Position).magnitude < Distance then
                    Torso = Temp
                    Distance = (Temp.Position - Position).magnitude
                end
            end
        end
    end
    return Torso
end




while true do
    local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position)
    if target ~= nil then
        script.Parent.Humanoid:MoveTo(target.Position, target)
    end
end

this should make the NPC follow the nearest player but it doesnt follow me when i tested it out.

0
this is not my script i got it from youtube bc i didn't know how to make it itzstarboss 9 — 3y
0
uh use runservice instead of while loop cos pro and u dont need the wait in the function. idk ;-; try printing stuf see wher it stop BulletproofVast 1033 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

OMG I AM so sorry everyone this was a mistake of mine one of the parts or something on the NPC Was anchored so that was why it coulden't move! sorry again but thanks anyways to all of the people that tried and wanted to help me

Ad

Answer this question