I have been working on a new project and wanted to incorporate pets or followers, However when I made them follow the players the pet kept walking into the player pushing the player. Is there a way I can make it so that they only follow the player if there is a big enough gap between the two? here is the script that I have been using
local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 30
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(0.1)
local target = findNearestTorso(script.Parent.Torso.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end

3 comments
Idk really how but I was thinking maybe you can have parts around the "pet" so the pet could not get too close..
But then the parts around the pet would push you
Just make the pet move to a certain distance away from the player than a body part of the player