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

Why is my NPC not moving at all when the player is in the area?[SOLVED]

Asked by 4 years ago
Edited 4 years ago

I'm trying to make an NPC move only if the character is within 10 studs of the NPC using magnitude and if it isn't then for it to wait until the player is within 10 studs. Any help? Here is my script.

for i,v in pairs(game.Players:GetChildren()) do
    if v and v.Character then
        local distance = 10
        while true do
        wait()
        if (script.Parent.UpperTorso.Position - v.Character.UpperTorso.Position).magnitude <= distance then
        script.Parent.Humanoid:MoveTo(v.Character.UpperTorso.Position)
    else
        repeat wait() until (script.Parent.UpperTorso.Position - v.Character.UpperTorso.Position).magnitude <= distance 
            end
        end
    end
end

1 answer

Log in to vote
0
Answered by 4 years ago

Never Mind i fixed it myself and it works!

Ad

Answer this question