I got these errors:  
	attempt to perform arithmetic on local 'x2' (a boolean value)  [DUP x4] 
	Bad argument @ 'getElementPosition' [Expected element at argument 1, got nil] 
	Bad argument @ 'getElementRotation' [Expected element at argument 1, got nil] 
	Bad argument @ 'getDistanceBetweenPoints3D' [Expected vector3 at argument 1, got boolean]
 
	 
 
setTimer(function(localPlayer)
  setPedFollow(myPed, localPlayer)
end, 1000, 0)
function setPedFollow(theElement, theTarget)
   if theElement then
      local x, y, z = getElementPosition(theTarget)
      local rx, ry, rz = getElementRotation(theTarget)
      local ex, ey, ez = getElementPosition(theElement)
      local distance = getDistanceBetweenPoints3D(x, y, z, ex, ey, ez)
      local rotation = findRotation(ex, ey, x, y)
      setPedRotation(theElement, rotation)
      if distance > 2 then
         setPedControlState(theElement, "forwards", true)
      else
         setPedControlState(theElement, "forwards", false)
      end
   end
end
function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end
	Thats the script. Why its not working