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

Trying to make a follow script that applies to NPC's around the player? [closed]

Asked by
Hizar7 102
6 years ago
game.Players.PlayerAdded:connect(function(Player)
local p = game.Workspace:WaitForChild(Player.Name)
print (p)
local f = p.UpperTorso.Position
print (f)
local dist = 15
local pos1 = f
        for i,v in pairs(game.Workspace.CrystalMobA.UndeadWarrior:GetChildren())do
         if v.Name == "HumanoidRootPart" then
            print (v)
            local z = v.Parent.Humanoid
            local pos2 = v.Position
            local magnitude = (pos1 - pos2).magnitude
            if magnitude <=15 and z then
            if p.Humanoid ~= nil then 
                print('humanoid')
                while true do
    wait(1)
    local target = f(v.Position)
    if target ~= nil then
        print ("Following")
        v.Parent.Humanoid:MoveTo(target.Position, target)
                        end
                    end
                end
            end
        end
    end
end)

Closed as Non-Descriptive by User#19524

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?