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

Why is :MoveTo() not working inside my Follow script??

Asked by 7 years ago

I watched a video on zombie that can follow you. It uses MoveTo.

I have some printers reporting who the closest target is, and they appear perfectly, but the zombie never follows me, without an error in both studio and public. Is there a way to fix this?

SCRIPT

local torso = script.Parent.Torso
local h = script.Parent.Humanoid
local spawncf = script.Parent.Torso.CFrame


function findPlayer()
    for _,v in next,game.Players:GetPlayers() do
        if v.Character then
            local char = v.Character

            if char:FindFirstChild("Humanoid") and char:FindFirstChild("Torso") then
                local ptorso = char.Torso

                if (ptorso.Position - torso.Position).magnitude <= 20 then
                    return v
                end
            end
        end
    end

    return nil
end

while wait() do
--  if findPlayer() ~= nil then
--      print(findPlayer().Name)
--  else
--      print("nil")
--  end

    local player = findPlayer()

    if player then
        h:MoveTo(player.Character.Torso.CFrame.p)
    else
        h:MoveTo(spawncf.p)
    end
end
0
If it is R15 you have to use UpperTorso instead of Torso on lines 1,3,11,12 and 34. mattscy 3725 — 7y
0
The rig is an R6 rig, sorry for not clarifying! ReadyHappiness 109 — 7y

Answer this question