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

I get no errors or Outputs but the code dummy follow dosen't work?

Asked by 5 years ago

So this script is supposed to be a npc following script as you can see it does not follow me it just stays still like nothing happened and no outputs either which makes it harder for me to tell what was done wrong

local torso = script.Parent.UpperTorso
local Humanoid = script.Parent.TestingDummy -- this is a humanoid
local SpawnCF = script.Parent.UpperTorso.CFrame

function findNearPlayer()
    for i,v in next,game.Players:GetPlayers() do
        if v.Character then
            local char = v.Character
            if char:FindFirstChild('Humanoid') and char:FindFirstChild('UpperTorso') then
                local Ptorso = char.UpperTorso
                if (Ptorso.Position - torso.Position).magnitude <= 8900000 then
                    return v




                end
            end
        end
    end
return nil
end


while wait() do
    local player = findNearPlayer()
    if player ~= nil then
        Humanoid:MoveTo(player.Character.UpperTorso.Position)
    else
        Humanoid:MoveTo(SpawnCF.p)
    end
end

0
The parameters of MoveTo() are location and part. You need to put a Vector3 position, and a part's position.You could also try :WalkToPoint(), if that's even a thing you can use in a script. ScrubSadmir 200 — 5y

Answer this question