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

Why doesn't my script to teleport npc behind player work?

Asked by 4 years ago
Edited 4 years ago

function module.DistanceFromKill() local nearestEnemy = nil local nearestRoot = math.huge workspace.SmilingKidWithRope.SmilingKid.Parent = workspace local root = workspace.SmilingKid.HumanoidRootPart for i, v in pairs(workspace.Game.People:GetChildren()) do local plrRoot = v:FindFirstChild("HumanoidRootPart")

        if plrRoot and plrRoot ~= root then
            local mag = (plrRoot.Position - root.Position).Magnitude
            if mag < 10 and mag < nearestRoot then
                nearestEnemy = plrRoot
                nearestRoot = mag
            end
        end
    end
if nearestEnemy then
    root.CFrame = nearestEnemy.CFrame * CFrame.new(0, 0, 3)
end

end

Theres also no errors

Answer this question